Fix copyright lines
[folly.git] / folly / compression / Compression.cpp
index 6f288b5ce5ade7bdaae9b8db96f5d2e4c4d39c53..4ad9f7956792f1e278fe5d73704222517fe34dc5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2017 Facebook, Inc.
+ * Copyright 2013-present Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -48,7 +48,6 @@
 #include <bzlib.h>
 #endif
 
-#include <folly/Bits.h>
 #include <folly/Conv.h>
 #include <folly/Memory.h>
 #include <folly/Portability.h>
@@ -56,6 +55,7 @@
 #include <folly/Varint.h>
 #include <folly/compression/Utils.h>
 #include <folly/io/Cursor.h>
+#include <folly/lang/Bits.h>
 #include <algorithm>
 #include <unordered_set>
 
@@ -1473,12 +1473,25 @@ void ZSTDStreamCodec::resetCStream() {
       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.
   // Required to set contentSizeFlag.
   auto params = ZSTD_getParams(level_, uncompressedLength().value_or(0), 0);
   params.fParams.contentSizeFlag = uncompressedLength().hasValue();
   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(