Implement Abort() in XZStream and relatives #15
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Abort()
method inXZStream
and its relatives.Details
Why current implementation does not have
Abort()
?My compression stream implementation follows .NET BCL's official DeflateStream interface. It does not define
Abort()
or similar method. Many other implementations also have a similar behavior.My guess is that zlib is a relatively fast compression algorithm, so merely calling
Close()
was enough even though a user wanted to abort the session.When and why
Close()
takes much time?When closing the
XZStream
(and its relatives),liblzma
flushes its internal buffer.In threaded compress mode,
liblzma
aggressively buffers the input data. The compression itself is merely postponed as much as possible. The compression time itself looks shorter, but it goes into the time needed to properly finalize an xz file.What does the new
Abort()
do?It just frees internal liblzma resources. To be exact, it frees
LzmaStream
, the context for the liblzma operation. It prevents any other liblzma operations from being conducted.Furthermore, calling
Abort()
preventsFlush()
andFinishWrite()
from being called inDispose()
/Close()
.It will save up some time on compress mode, especially threaded compression mode. It does not in decompress mode.
liblzma will refuse any operation after calling
Abort()
.Users must dispose of
XZStream
right after callingAbort()
. The compressed data will be invalid and must be discarded.Benchmark: How much does
Abort()
save time compared toClose()
?Taken from the
AbortCompress
test prints: