Commit 2c8c7ee0 authored by Nick Terrell's avatar Nick Terrell Committed by Facebook Github Bot

Pass ZSTD_CONTENTSIZE_UNKNOWN

Summary:
Content size 0 as unknown is deprecated.
See code comments for details.

Reviewed By: felixhandte

Differential Revision: D6521582

fbshipit-source-id: 876b94cc0123c1020b456cc8f4cd86997afe0619
parent 712b8b8d
...@@ -1473,12 +1473,25 @@ void ZSTDStreamCodec::resetCStream() { ...@@ -1473,12 +1473,25 @@ void ZSTDStreamCodec::resetCStream() {
throw std::bad_alloc{}; throw std::bad_alloc{};
} }
} }
// As of 1.3.2 ZSTD_initCStream_advanced() interprets content size 0 as
// unknown if contentSizeFlag == 0, but this behavior is deprecated, and will
// be removed in the future. Starting with version 1.3.2 start passing the
// correct value, ZSTD_CONTENTSIZE_UNKNOWN.
#if ZSTD_VERSION_NUMBER >= 10302
constexpr uint64_t kZstdUnknownContentSize = ZSTD_CONTENTSIZE_UNKNOWN;
#else
constexpr uint64_t kZstdUnknownContentSize = 0;
#endif
// Advanced API usage works for all supported versions of zstd. // Advanced API usage works for all supported versions of zstd.
// Required to set contentSizeFlag. // Required to set contentSizeFlag.
auto params = ZSTD_getParams(level_, uncompressedLength().value_or(0), 0); auto params = ZSTD_getParams(level_, uncompressedLength().value_or(0), 0);
params.fParams.contentSizeFlag = uncompressedLength().hasValue(); params.fParams.contentSizeFlag = uncompressedLength().hasValue();
zstdThrowIfError(ZSTD_initCStream_advanced( zstdThrowIfError(ZSTD_initCStream_advanced(
cstream_.get(), nullptr, 0, params, uncompressedLength().value_or(0))); cstream_.get(),
nullptr,
0,
params,
uncompressedLength().value_or(kZstdUnknownContentSize)));
} }
bool ZSTDStreamCodec::doCompressStream( bool ZSTDStreamCodec::doCompressStream(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment