I have a function that collects, compress, writes data to a buffer.
const bound = try encoding.compressBound(self.uncompressedMetaindexBuf.items.len);
try self.metaindexBuf.ensureUnusedCapacity(bound);
try self.metaindexBuf.writer.ensureUnusedCapacity(bound);
const n = try encoding.compressAuto(
self.metaindexBuf.unusedCapacitySlice(),
self.uncompressedMetaindexBuf.items,
);
self.metaindexBuf.items.len += n;
Here I compress, preallocate at once and write to the destination the content.
Now I need a file as a destination, so it feels correct to use Writer, but
- Writer doesn’t support “close” api, so it means I have to hold a link to a file to close it? so it means I hold them nullable, and if I have 3 destination implementations (e.g. ArrayList, File and S3) then I might have 3 fields per buffer to hold different deinit, and I have 4 of them, so it’s 12 fields in total only for deinit?
- no direct access to a file buffer, therefore I need to allocate an intermediate buffer to write a compressed content and then write the buffer to a file/destination array, right? can I trick somehow the implementation to use a file’s buffer, in streaming mode write compression and avoid intermediate buffer allocation?