Optimize stream for full-file writes

This commit is contained in:
topjohnwu
2021-11-23 18:08:14 -08:00
parent 048b2af0fc
commit 24984ea4f2
5 changed files with 50 additions and 23 deletions

View File

@@ -26,6 +26,7 @@ public:
ssize_t read(void *buf, size_t len) override;
bool write(const void *buf, size_t len) override;
virtual bool write(const void *buf, size_t len, bool final);
// Seeking while filtering does not make sense
off_t seek(off_t off, int whence) final { return stream::seek(off, whence); }
@@ -34,6 +35,8 @@ protected:
stream_ptr base;
};
using filter_strm_ptr = std::unique_ptr<filter_stream>;
// Buffered output stream, writing in chunks
class chunk_out_stream : public filter_stream {
public:
@@ -48,11 +51,12 @@ public:
// Reading does not make sense
ssize_t read(void *buf, size_t len) final { return stream::read(buf, len); }
bool write(const void *buf, size_t len) final;
bool write(const void *buf, size_t len, bool final) final;
protected:
// Classes inheriting this class has to call finalize() in its destructor
void finalize();
virtual bool write_chunk(const void *buf, size_t len) = 0;
virtual bool write_chunk(const void *buf, size_t len, bool final) = 0;
size_t chunk_sz;