1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/vm/Compression.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,55 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * vim: set ts=8 sts=4 et sw=4 tw=99: 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef vm_Compression_h 1.11 +#define vm_Compression_h 1.12 + 1.13 +#ifdef USE_ZLIB 1.14 + 1.15 +#include <zlib.h> 1.16 + 1.17 +#include "jstypes.h" 1.18 + 1.19 +namespace js { 1.20 + 1.21 +class Compressor 1.22 +{ 1.23 + /* Number of bytes we should hand to zlib each compressMore() call. */ 1.24 + static const size_t CHUNKSIZE = 2048; 1.25 + z_stream zs; 1.26 + const unsigned char *inp; 1.27 + size_t inplen; 1.28 + size_t outbytes; 1.29 + bool initialized; 1.30 + 1.31 + public: 1.32 + enum Status { 1.33 + MOREOUTPUT, 1.34 + DONE, 1.35 + CONTINUE, 1.36 + OOM 1.37 + }; 1.38 + 1.39 + Compressor(const unsigned char *inp, size_t inplen); 1.40 + ~Compressor(); 1.41 + bool init(); 1.42 + void setOutput(unsigned char *out, size_t outlen); 1.43 + size_t outWritten() const { return outbytes; } 1.44 + /* Compress some of the input. Return true if it should be called again. */ 1.45 + Status compressMore(); 1.46 +}; 1.47 + 1.48 +/* 1.49 + * Decompress a string. The caller must know the length of the output and 1.50 + * allocate |out| to a string of that length. 1.51 + */ 1.52 +bool DecompressString(const unsigned char *inp, size_t inplen, 1.53 + unsigned char *out, size_t outlen); 1.54 + 1.55 +} /* namespace js */ 1.56 + 1.57 +#endif /* USE_ZLIB */ 1.58 +#endif /* vm_Compression_h */