mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-12-12 14:55:20 +00:00
Cleanup filter_out_stream implementation
This commit is contained in:
@@ -18,16 +18,11 @@ using out_strm_ptr = std::unique_ptr<out_stream>;
|
||||
class filter_out_stream : public out_stream {
|
||||
public:
|
||||
filter_out_stream(out_strm_ptr &&base) : base(std::move(base)) {}
|
||||
|
||||
bool write(const void *buf, size_t len) override;
|
||||
virtual bool write(const void *buf, size_t len, bool final);
|
||||
|
||||
protected:
|
||||
out_strm_ptr base;
|
||||
};
|
||||
|
||||
using filter_strm_ptr = std::unique_ptr<filter_out_stream>;
|
||||
|
||||
// Buffered output stream, writing in chunks
|
||||
class chunk_out_stream : public filter_out_stream {
|
||||
public:
|
||||
@@ -40,7 +35,6 @@ public:
|
||||
~chunk_out_stream() override { delete[] _buf; }
|
||||
|
||||
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
|
||||
@@ -63,7 +57,7 @@ struct in_stream {
|
||||
};
|
||||
|
||||
// A channel is something that is writable, readable, and seekable
|
||||
struct channel : public in_stream, public out_stream {
|
||||
struct channel : public out_stream, public in_stream {
|
||||
virtual off_t seek(off_t off, int whence) = 0;
|
||||
virtual ~channel() = default;
|
||||
};
|
||||
|
||||
@@ -88,15 +88,7 @@ bool filter_out_stream::write(const void *buf, size_t len) {
|
||||
return base->write(buf, len);
|
||||
}
|
||||
|
||||
bool filter_out_stream::write(const void *buf, size_t len, bool final) {
|
||||
return write(buf, len);
|
||||
}
|
||||
|
||||
bool chunk_out_stream::write(const void *buf, size_t len) {
|
||||
return write(buf, len, false);
|
||||
}
|
||||
|
||||
bool chunk_out_stream::write(const void *_in, size_t len, bool final) {
|
||||
bool chunk_out_stream::write(const void *_in, size_t len) {
|
||||
auto in = static_cast<const uint8_t *>(_in);
|
||||
while (len) {
|
||||
if (buf_off + len >= chunk_sz) {
|
||||
@@ -114,21 +106,8 @@ bool chunk_out_stream::write(const void *_in, size_t len, bool final) {
|
||||
in += chunk_sz;
|
||||
len -= chunk_sz;
|
||||
}
|
||||
if (!write_chunk(src, chunk_sz, final && len == 0))
|
||||
if (!write_chunk(src, chunk_sz, false))
|
||||
return false;
|
||||
} else if (final) {
|
||||
// Final input data, write regardless whether it is chunk sized
|
||||
if (buf_off) {
|
||||
memcpy(_buf + buf_off, in, len);
|
||||
auto avail = buf_off + len;
|
||||
buf_off = 0;
|
||||
if (!write_chunk(_buf, avail, true))
|
||||
return false;
|
||||
} else {
|
||||
if (!write_chunk(in, len, true))
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
// Buffer internally
|
||||
if (!_buf) {
|
||||
|
||||
Reference in New Issue
Block a user