1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/Compression.h"
8 #include "mozilla/CheckedInt.h"
10 using namespace mozilla::Compression
;
16 }/* anonymous namespace */
21 LZ4::compress(const char* aSource
, size_t aInputSize
, char* aDest
)
23 CheckedInt
<int> inputSizeChecked
= aInputSize
;
24 MOZ_ASSERT(inputSizeChecked
.isValid());
25 return LZ4_compress(aSource
, aDest
, inputSizeChecked
.value());
29 LZ4::compressLimitedOutput(const char* aSource
, size_t aInputSize
, char* aDest
,
30 size_t aMaxOutputSize
)
32 CheckedInt
<int> inputSizeChecked
= aInputSize
;
33 MOZ_ASSERT(inputSizeChecked
.isValid());
34 CheckedInt
<int> maxOutputSizeChecked
= aMaxOutputSize
;
35 MOZ_ASSERT(maxOutputSizeChecked
.isValid());
36 return LZ4_compress_limitedOutput(aSource
, aDest
, inputSizeChecked
.value(),
37 maxOutputSizeChecked
.value());
41 LZ4::decompress(const char* aSource
, char* aDest
, size_t aOutputSize
)
43 CheckedInt
<int> outputSizeChecked
= aOutputSize
;
44 MOZ_ASSERT(outputSizeChecked
.isValid());
45 int ret
= LZ4_decompress_fast(aSource
, aDest
, outputSizeChecked
.value());
50 LZ4::decompress(const char* aSource
, size_t aInputSize
, char* aDest
,
51 size_t aMaxOutputSize
, size_t* aOutputSize
)
53 CheckedInt
<int> maxOutputSizeChecked
= aMaxOutputSize
;
54 MOZ_ASSERT(maxOutputSizeChecked
.isValid());
55 CheckedInt
<int> inputSizeChecked
= aInputSize
;
56 MOZ_ASSERT(inputSizeChecked
.isValid());
58 int ret
= LZ4_decompress_safe(aSource
, aDest
, inputSizeChecked
.value(),
59 maxOutputSizeChecked
.value());