michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * vim: set ts=8 sts=4 et sw=4 tw=99: michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef vm_Compression_h michael@0: #define vm_Compression_h michael@0: michael@0: #ifdef USE_ZLIB michael@0: michael@0: #include michael@0: michael@0: #include "jstypes.h" michael@0: michael@0: namespace js { michael@0: michael@0: class Compressor michael@0: { michael@0: /* Number of bytes we should hand to zlib each compressMore() call. */ michael@0: static const size_t CHUNKSIZE = 2048; michael@0: z_stream zs; michael@0: const unsigned char *inp; michael@0: size_t inplen; michael@0: size_t outbytes; michael@0: bool initialized; michael@0: michael@0: public: michael@0: enum Status { michael@0: MOREOUTPUT, michael@0: DONE, michael@0: CONTINUE, michael@0: OOM michael@0: }; michael@0: michael@0: Compressor(const unsigned char *inp, size_t inplen); michael@0: ~Compressor(); michael@0: bool init(); michael@0: void setOutput(unsigned char *out, size_t outlen); michael@0: size_t outWritten() const { return outbytes; } michael@0: /* Compress some of the input. Return true if it should be called again. */ michael@0: Status compressMore(); michael@0: }; michael@0: michael@0: /* michael@0: * Decompress a string. The caller must know the length of the output and michael@0: * allocate |out| to a string of that length. michael@0: */ michael@0: bool DecompressString(const unsigned char *inp, size_t inplen, michael@0: unsigned char *out, size_t outlen); michael@0: michael@0: } /* namespace js */ michael@0: michael@0: #endif /* USE_ZLIB */ michael@0: #endif /* vm_Compression_h */