Overview
| Artifact ID: | 7fa4bde9221a5b8e0e72aca27edeba9a61c8cc22fa417f57db38bc9c6dc01cc0 |
|---|---|
| Ticket: | f70ce1feadf55c2f0fd142bdc20fbdcae5698495
zlib transform issue, multi-stream inflate ignores streams after first |
| User & Date: | aku on 2020-04-16 06:53:41 |
Changes
- icomment:
Updated patch. In addition to signaling the stream end it also records how much of the last read was processed, and how much was not, i.e. read beyond the end of the stream (over'shot). When the transform closes (is popped off) this excess data is stashed back into the underlying channel, to be read either plain, or by the next transform push onto it. This change makes the `-limit` option superfluous. We can read as much as we like. For backward compatibility we should keep accepting it in all releases before v9, just ignore the value, use something automatic (buffer size ?). In v9 we can drop it. Passes `make test`. Even so, this and previous ticket really need test cases to demo them added to zlib.test. Not today however, need sleep. <pre> Index: generic/tclZlib.c ================================================================== --- generic/tclZlib.c +++ generic/tclZlib.c @@ -126,10 +126,16 @@ Tcl_TimerToken timer; /* Timer used for keeping events fresh. */ Tcl_DString decompressed; /* Buffer for decompression results. */ Tcl_Obj *compDictObj; /* Byte-array object containing compression * dictionary (not dictObj!) to use if * necessary. */ + int done; /* Flag to signal stream end up to transform + * input */ + int over; /* Number of bytes we read to far in the + * underlying stream */ + int skip; /* Bytes processed in the last read before + * the overshot */ } ZlibChannelData; /* * Value bits for the flags field. Definitions are: * ASYNC - Whether this is an asynchronous channel. @@ -2946,10 +2952,14 @@ } while (e != Z_STREAM_END); (void) deflateEnd(&cd->outStream); } else { (void) inflateEnd(&cd->inStream); } + + if (cd->over) { + Tcl_Ungets (cd->parent, cd->inBuffer + cd->skip, cd->over, 0); + } /* * Release all memory. */ @@ -3011,10 +3021,14 @@ gotBytes += copied; if (toRead == 0) { return gotBytes; } + + if (cd->done) { + return gotBytes; + } /* * The buffer is exhausted, but the caller wants even more. We now * have to go to the underlying channel, get more bytes and then * transform them for delivery. We may not get what we want (full EOF @@ -3831,10 +3845,15 @@ */ if (((flush == Z_SYNC_FLUSH) && (e == Z_BUF_ERROR)) || (e == Z_STREAM_END) || (e == Z_OK && written == 0)) { + if (e == Z_STREAM_END) { + cd->done = 1; + cd->over = cd->inStream.avail_in; + cd->skip = n - cd->over; + } return TCL_OK; } /* * Z_BUF_ERROR can be ignored as per http://www.zlib.net/zlib_how.html </pre> - login: "aku"
- mimetype: "text/x-fossil-wiki"