https://issues.dlang.org/show_bug.cgi?id=18773
SHOO <[email protected]> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |[email protected] --- Comment #1 from SHOO <[email protected]> --- This issue seems to be implementation problems rather than undocumented restrictions: since the argument of compress/uncompress is requiring const(void)[], the function has to take into account the possibility that the buffer may be changed. Specifically, the following code does not work: ----------------------------------------------- auto compressed = appender!(ubyte[])(); scope compress = new Compress(HeaderFormat.gzip); char[128] buffer; foreach (e; ["abc", "abcdefghijk"]) { auto line = sformat!"%s\n"(buffer, e); // Invalid buffer is held by Compress const compressedLine = compress.compress(line); compressed.put(cast(const(ubyte)[]) compressedLine); } compressed.put(cast(const(ubyte)[]) compress.flush()); ----------------------------------------------- To solve this, there are two policies: 1. Change the type of argument to immutable(void)[] (this is a breaking change) 2. Copy the argument's buffer, and manage the life of the copied buffer in Compress/UnCompress. --
