├── deps └── snappy │ ├── snappy-1.1.7 │ ├── AUTHORS │ ├── cmake │ │ ├── SnappyConfig.cmake │ │ └── config.h.in │ ├── CONTRIBUTING.md │ ├── .appveyor.yml │ ├── .travis.yml │ ├── snappy-stubs-internal.cc │ ├── COPYING │ ├── snappy-stubs-public.h.in │ ├── snappy-sinksource.cc │ ├── snappy-c.cc │ ├── format_description.txt │ ├── framing_format.txt │ ├── snappy-c.h │ ├── CMakeLists.txt │ ├── NEWS │ ├── README.md │ ├── snappy-sinksource.h │ ├── snappy-internal.h │ ├── snappy.h │ ├── snappy-test.h │ └── snappy-stubs-internal.h │ ├── common.gypi │ ├── snappy.gyp │ ├── linux │ ├── ppc64le │ │ ├── config.h │ │ └── snappy-stubs-public.h │ ├── ppc64 │ │ ├── config.h │ │ └── snappy-stubs-public.h │ ├── s390x │ │ ├── config.h │ │ └── snappy-stubs-public.h │ └── generic │ │ ├── config.h │ │ └── snappy-stubs-public.h │ ├── freebsd │ ├── config.h │ └── snappy-stubs-public.h │ ├── mac │ ├── config.h │ └── snappy-stubs-public.h │ ├── solaris │ ├── config.h │ └── snappy-stubs-public.h │ └── win32 │ ├── config.h │ └── snappy-stubs-public.h ├── .npmignore ├── benchmark ├── package.json └── benchmark.js ├── CHANGELOG.md ├── tsconfig.json ├── src ├── binding.h └── binding.cc ├── .travis.yml ├── examples └── string.js ├── binding.gyp ├── appveyor.yml ├── .gitignore ├── snappy.d.ts ├── LICENSE ├── package.json ├── snappy.js ├── test.js └── readme.md /deps/snappy/snappy-1.1.7/AUTHORS: -------------------------------------------------------------------------------- 1 | opensource@google.com 2 | -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.7/cmake/SnappyConfig.cmake: -------------------------------------------------------------------------------- 1 | include("${CMAKE_CURRENT_LIST_DIR}/SnappyTargets.cmake") -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .git* 2 | .npmignore 3 | .travis.yml 4 | 5 | *.log 6 | 7 | benchmark/ 8 | build/ 9 | examples/ 10 | node_modules/ 11 | test/ 12 | -------------------------------------------------------------------------------- /benchmark/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "async-benchmark": "^1.0.0", 4 | "bytes": "^1.0.0", 5 | "chalk": "^0.5.1", 6 | "run-series": "^1.0.2" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## v6 4 | - Drop support for 0.10 & 0.12 5 | - update snappy version 6 | 7 | ## v5 8 | 9 | - Drop support for iojs & node 0.8 10 | - bugfixes 11 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "files": ["./snappy.js"], 3 | 4 | "compilerOptions": { 5 | "allowJs": true, 6 | "declaration": true, 7 | "emitDeclarationOnly": true, 8 | "strict": false 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/binding.h: -------------------------------------------------------------------------------- 1 | #ifndef __NODE_SNAPPY_BINDING_H__ 2 | #define __NODE_SNAPPY_BINDING_H__ 3 | #include 4 | #include 5 | #include 6 | #include "nan.h" 7 | 8 | namespace nodesnappy { 9 | 10 | } // namespace nodesnappy 11 | 12 | #endif /* __NODE_SNAPPY_BINDING_H__ */ 13 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | before_install: 3 | - export JOBS=max 4 | 5 | install: 6 | # use npm ci if available 7 | - npm ci || npm i 8 | # keep the npm cache around to speed up installs 9 | cache: 10 | directories: 11 | - "$HOME/.npm" 12 | 13 | os: 14 | - osx 15 | - linux 16 | 17 | node_js: 18 | - 4 19 | - 6 20 | - 8 21 | - 10 22 | - 12 23 | - 14 24 | - node 25 | -------------------------------------------------------------------------------- /examples/string.js: -------------------------------------------------------------------------------- 1 | var snappy = require('..'); // require('snappy') 2 | 3 | snappy.compress('beep boop', function (err, compressed) { 4 | if (err) { 5 | throw err; 6 | } 7 | console.log('compressed is a Buffer', compressed); 8 | // return it as a string 9 | snappy.uncompress(compressed, { 10 | asBuffer: false 11 | }, function (err, original) { 12 | if (err) { 13 | throw err; 14 | } 15 | console.log('the original String', original); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /binding.gyp: -------------------------------------------------------------------------------- 1 | { 2 | 'targets': [ 3 | { 4 | 'target_name': 'binding', 5 | 'includes': [ 'deps/snappy/common.gypi' ], 6 | 'include_dirs': [ ' void): void; 2 | export function compressSync(input: string | Buffer): Buffer; 3 | 4 | export var isValidCompressed: (buffer: Buffer, callback: (err: Error | null, isValid?: boolean) => void) => void; 5 | export var isValidCompressedSync: (buffer: Buffer) => boolean; 6 | 7 | export function uncompress(compressed: Buffer, callback: (err: Error, uncompressed?: Buffer) => void): void; 8 | export function uncompress(compressed: Buffer, opts: {asBuffer: false}, callback: (err: Error, uncompressed?: string) => void): void; 9 | export function uncompress(compressed: Buffer, opts: {asBuffer: true}, callback: (err: Error, uncompressed?: Buffer) => void): void; 10 | 11 | export function uncompressSync(compressed: Buffer): Buffer; 12 | export function uncompressSync(compressed: Buffer, opts: {asBuffer: false} ): string; 13 | export function uncompressSync(compressed: Buffer, opts: {asBuffer: true} ): Buffer; 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) Björklund David 2 | 3 | This software is released under the MIT license: 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.7/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to Contribute 2 | 3 | We'd love to accept your patches and contributions to this project. There are 4 | just a few small guidelines you need to follow. 5 | 6 | ## Contributor License Agreement 7 | 8 | Contributions to this project must be accompanied by a Contributor License 9 | Agreement. You (or your employer) retain the copyright to your contribution, 10 | this simply gives us permission to use and redistribute your contributions as 11 | part of the project. Head over to to see 12 | your current agreements on file or to sign a new one. 13 | 14 | You generally only need to submit a CLA once, so if you've already submitted one 15 | (even if it was for a different project), you probably don't need to do it 16 | again. 17 | 18 | ## Code reviews 19 | 20 | All submissions, including submissions by project members, require review. We 21 | use GitHub pull requests for this purpose. Consult 22 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more 23 | information on using pull requests. 24 | 25 | Please make sure that all the automated checks (CLA, AppVeyor, Travis) pass for 26 | your pull requests. Pull requests whose checks fail may be ignored. 27 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "author": "David Björklund ", 3 | "name": "snappy", 4 | "description": "Nodejs bindings to Google's Snappy compression library", 5 | "version": "6.3.5", 6 | "homepage": "https://github.com/kesla/node-snappy", 7 | "repository": { 8 | "type": "git", 9 | "url": "git://github.com/kesla/node-snappy.git" 10 | }, 11 | "main": "snappy.js", 12 | "scripts": { 13 | "pretest": "node-gyp rebuild", 14 | "test": "nyc ava test.js && semistandard | snazzy && prebuild-ci", 15 | "install": "prebuild-install || node-gyp rebuild", 16 | "rebuild": "prebuild --compile", 17 | "prebuild": "prebuild --all --strip --verbose", 18 | "prepublishOnly": "tsc" 19 | }, 20 | "dependencies": { 21 | "bindings": "^1.3.1", 22 | "nan": "^2.14.1", 23 | "prebuild-install": "5.3.0" 24 | }, 25 | "devDependencies": { 26 | "@types/node": "^13.13.1", 27 | "ava": "^0.25.0", 28 | "bluebird": "^3.5.3", 29 | "nyc": "^11.9.0", 30 | "prebuild": "^8.2.1", 31 | "prebuild-ci": "^2.3.0", 32 | "semistandard": "^11.0.0", 33 | "snazzy": "^7.1.1" 34 | }, 35 | "gypfile": true, 36 | "bugs": { 37 | "url": "https://github.com/kesla/node-snappy/issues" 38 | }, 39 | "license": "MIT" 40 | } 41 | -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.7/.appveyor.yml: -------------------------------------------------------------------------------- 1 | # Build matrix / environment variables are explained on: 2 | # https://www.appveyor.com/docs/appveyor-yml/ 3 | # This file can be validated on: https://ci.appveyor.com/tools/validate-yaml 4 | 5 | version: "{build}" 6 | 7 | environment: 8 | matrix: 9 | # AppVeyor currently has no custom job name feature. 10 | # http://help.appveyor.com/discussions/questions/1623-can-i-provide-a-friendly-name-for-jobs 11 | - JOB: Visual Studio 2017 12 | APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 13 | CMAKE_GENERATOR: Visual Studio 15 2017 14 | - JOB: Visual Studio 2015 15 | APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 16 | CMAKE_GENERATOR: Visual Studio 14 2015 17 | 18 | platform: 19 | - x86 20 | - x64 21 | 22 | configuration: 23 | - RelWithDebInfo 24 | - Debug 25 | 26 | build: 27 | verbosity: minimal 28 | 29 | build_script: 30 | - git submodule update --init --recursive 31 | - mkdir out 32 | - cd out 33 | - if "%platform%"=="x64" set CMAKE_GENERATOR=%CMAKE_GENERATOR% Win64 34 | - cmake --version 35 | - cmake .. -G "%CMAKE_GENERATOR%" 36 | -DCMAKE_CONFIGURATION_TYPES="%CONFIGURATION%" 37 | - cmake --build . --config %CONFIGURATION% 38 | - cd .. 39 | 40 | test_script: 41 | - out\%CONFIGURATION%\snappy_unittest -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.7/.travis.yml: -------------------------------------------------------------------------------- 1 | # Build matrix / environment variables are explained on: 2 | # http://about.travis-ci.org/docs/user/build-configuration/ 3 | # This file can be validated on: http://lint.travis-ci.org/ 4 | 5 | sudo: false 6 | dist: trusty 7 | language: cpp 8 | 9 | compiler: 10 | - gcc 11 | - clang 12 | os: 13 | - linux 14 | - osx 15 | 16 | env: 17 | - BUILD_TYPE=Debug 18 | - BUILD_TYPE=RelWithDebInfo 19 | 20 | matrix: 21 | allow_failures: 22 | - compiler: clang 23 | env: BUILD_TYPE=RelWithDebInfo 24 | 25 | addons: 26 | apt: 27 | # List of whitelisted in travis packages for ubuntu-trusty can be found here: 28 | # https://github.com/travis-ci/apt-package-whitelist/blob/master/ubuntu-trusty 29 | # List of whitelisted in travis apt-sources: 30 | # https://github.com/travis-ci/apt-source-whitelist/blob/master/ubuntu.json 31 | sources: 32 | - ubuntu-toolchain-r-test 33 | - llvm-toolchain-trusty-4.0 34 | packages: 35 | - cmake 36 | - gcc-6 37 | - g++-6 38 | - clang-4.0 39 | 40 | install: 41 | # Travis doesn't have a nice way to install homebrew packages yet. 42 | # https://github.com/travis-ci/travis-ci/issues/5377 43 | - if [ "$TRAVIS_OS_NAME" == "osx" ]; then brew update; fi 44 | - if [ "$TRAVIS_OS_NAME" == "osx" ]; then brew install gcc@6; fi 45 | # /usr/bin/gcc is stuck to old versions by on both Linux and OSX. 46 | - if [ "$CXX" = "g++" ]; then export CXX="g++-6" CC="gcc-6"; fi 47 | - echo ${CC} 48 | - echo ${CXX} 49 | - ${CXX} --version 50 | - cmake --version 51 | 52 | before_script: 53 | - mkdir -p build && cd build 54 | - cmake .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE 55 | - cmake --build . 56 | - cd .. 57 | 58 | script: 59 | - build/snappy_unittest -------------------------------------------------------------------------------- /deps/snappy/snappy.gyp: -------------------------------------------------------------------------------- 1 | { 2 | 'includes': [ 'common.gypi' ], 3 | 'targets': [{ 4 | 'target_name': 'snappy', 5 | 'type': 'static_library', 6 | 7 | # Overcomes an issue with the linker and thin .a files on SmartOS 8 | 'standalone_static_library': 1, 9 | 'include_dirs': [ '<(os_include)', 'snappy-1.1.7' ], 10 | 'direct_dependent_settings': { 11 | 'include_dirs': [ 'snappy-1.1.7' ] 12 | }, 13 | 'defines': [ 'HAVE_CONFIG_H=1' ], 14 | 'conditions': [ 15 | ['OS == "win"', { 16 | 'defines': [ '_HAS_EXCEPTIONS=0' ], 17 | 'msvs_settings': { 18 | 'VCCLCompilerTool': { 19 | 'RuntimeTypeInfo': 'false', 20 | 'EnableFunctionLevelLinking': 'true', 21 | 'ExceptionHandling': '2', 22 | 'DisableSpecificWarnings': [ '4355', '4530' ,'4267', '4244', '4506', '4018' ] 23 | } 24 | } 25 | }], 26 | ['OS == "linux"', { 27 | 'cflags': [ '-Wno-sign-compare', '-Wno-unused-function' ], 28 | 'cflags!': [ '-fno-tree-vrp' ] 29 | }], 30 | ['OS == "freebsd"', { 31 | 'cflags': [ '-Wno-sign-compare', '-Wno-unused-function' ] 32 | }], 33 | ['OS == "solaris"', { 34 | 'cflags': [ '-Wno-sign-compare', '-Wno-unused-function' ] 35 | }], 36 | ['OS == "mac"', { 37 | 'xcode_settings': { 38 | 'WARNING_CFLAGS': [ '-Wno-sign-compare', '-Wno-unused-function' ], 39 | 'MACOSX_DEPLOYMENT_TARGET': '10.9' 40 | } 41 | }] 42 | ], 43 | 'sources': [ 44 | 'snappy-1.1.7/snappy-internal.h', 45 | 'snappy-1.1.7/snappy-sinksource.cc', 46 | 'snappy-1.1.7/snappy-sinksource.h', 47 | 'snappy-1.1.7/snappy-stubs-internal.cc', 48 | 'snappy-1.1.7/snappy-stubs-internal.h', 49 | 'snappy-1.1.7/snappy.cc', 50 | 'snappy-1.1.7/snappy.h' 51 | ] 52 | }] 53 | } 54 | -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.7/snappy-stubs-internal.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. All Rights Reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of Google Inc. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #include 30 | #include 31 | 32 | #include "snappy-stubs-internal.h" 33 | 34 | namespace snappy { 35 | 36 | void Varint::Append32(string* s, uint32 value) { 37 | char buf[Varint::kMax32]; 38 | const char* p = Varint::Encode32(buf, value); 39 | s->append(buf, p - buf); 40 | } 41 | 42 | } // namespace snappy 43 | -------------------------------------------------------------------------------- /deps/snappy/linux/ppc64le/config.h: -------------------------------------------------------------------------------- 1 | #ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_ 2 | #define THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_ 3 | 4 | /* Define to 1 if the compiler supports __builtin_ctz and friends. */ 5 | #define HAVE_BUILTIN_CTZ 1 6 | 7 | /* Define to 1 if the compiler supports __builtin_expect. */ 8 | #define HAVE_BUILTIN_EXPECT 1 9 | 10 | /* Define to 1 if you have the header file. */ 11 | #define HAVE_BYTESWAP_H 1 12 | 13 | /* Define to 1 if you have a definition for mmap() in . */ 14 | #define HAVE_FUNC_MMAP 1 15 | 16 | /* Define to 1 if you have a definition for sysconf() in . */ 17 | #define HAVE_FUNC_SYSCONF 1 18 | 19 | /* Define to 1 to use the gflags package for command-line parsing. */ 20 | /* #undef HAVE_GFLAGS */ 21 | 22 | /* Define to 1 if you have Google Test. */ 23 | /* #undef HAVE_GTEST */ 24 | 25 | /* Define to 1 if you have the `lzo2' library (-llzo2). */ 26 | /* #undef HAVE_LIBLZO2 */ 27 | 28 | /* Define to 1 if you have the `z' library (-lz). */ 29 | #define HAVE_LIBZ 1 30 | 31 | /* Define to 1 if you have the header file. */ 32 | /* #undef HAVE_SYS_ENDIAN_H */ 33 | 34 | /* Define to 1 if you have the header file. */ 35 | #define HAVE_SYS_MMAN_H 1 36 | 37 | /* Define to 1 if you have the header file. */ 38 | #define HAVE_SYS_RESOURCE_H 1 39 | 40 | /* Define to 1 if you have the header file. */ 41 | #define HAVE_SYS_TIME_H 1 42 | 43 | /* Define to 1 if you have the header file. */ 44 | #define HAVE_SYS_UIO_H 1 45 | 46 | /* Define to 1 if you have the header file. */ 47 | #define HAVE_UNISTD_H 1 48 | 49 | /* Define to 1 if you have the header file. */ 50 | /* #undef HAVE_WINDOWS_H */ 51 | 52 | /* Define to 1 if you target processors with SSSE3+ and have . */ 53 | #define SNAPPY_HAVE_SSSE3 0 54 | 55 | /* Define to 1 if your processor stores words with the most significant byte 56 | first (like Motorola and SPARC, unlike Intel and VAX). */ 57 | /* #undef SNAPPY_IS_BIG_ENDIAN */ 58 | 59 | #endif // THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_ 60 | -------------------------------------------------------------------------------- /deps/snappy/freebsd/config.h: -------------------------------------------------------------------------------- 1 | #ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_ 2 | #define THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_ 3 | 4 | /* Define to 1 if the compiler supports __builtin_ctz and friends. */ 5 | #define HAVE_BUILTIN_CTZ 1 6 | 7 | /* Define to 1 if the compiler supports __builtin_expect. */ 8 | #define HAVE_BUILTIN_EXPECT 1 9 | 10 | /* Define to 1 if you have the header file. */ 11 | /* #undef HAVE_BYTESWAP_H */ 12 | 13 | /* Define to 1 if you have a definition for mmap() in . */ 14 | #define HAVE_FUNC_MMAP 1 15 | 16 | /* Define to 1 if you have a definition for sysconf() in . */ 17 | #define HAVE_FUNC_SYSCONF 1 18 | 19 | /* Define to 1 to use the gflags package for command-line parsing. */ 20 | /* #undef HAVE_GFLAGS */ 21 | 22 | /* Define to 1 if you have Google Test. */ 23 | /* #undef HAVE_GTEST */ 24 | 25 | /* Define to 1 if you have the `lzo2' library (-llzo2). */ 26 | /* #undef HAVE_LIBLZO2 */ 27 | 28 | /* Define to 1 if you have the `z' library (-lz). */ 29 | #define HAVE_LIBZ 1 30 | 31 | /* Define to 1 if you have the header file. */ 32 | #define HAVE_STDDEF_H 1 33 | 34 | /* Define to 1 if you have the header file. */ 35 | #define HAVE_STDINT_H 1 36 | 37 | /* Define to 1 if you have the header file. */ 38 | #define HAVE_SYS_ENDIAN_H 1 39 | 40 | /* Define to 1 if you have the header file. */ 41 | #define HAVE_SYS_MMAN_H 1 42 | 43 | /* Define to 1 if you have the header file. */ 44 | #define HAVE_SYS_RESOURCE_H 1 45 | 46 | /* Define to 1 if you have the header file. */ 47 | #define HAVE_SYS_TIME_H 1 48 | 49 | /* Define to 1 if you have the header file. */ 50 | #define HAVE_SYS_UIO_H 1 51 | 52 | /* Define to 1 if you have the header file. */ 53 | #define HAVE_UNISTD_H 1 54 | 55 | /* Define to 1 if you have the header file. */ 56 | /* #undef HAVE_WINDOWS_H */ 57 | 58 | /* Define to 1 if your processor stores words with the most significant byte 59 | first (like Motorola and SPARC, unlike Intel and VAX). */ 60 | /* #undef SNAPPY_IS_BIG_ENDIAN */ 61 | 62 | #endif // THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_ 63 | -------------------------------------------------------------------------------- /deps/snappy/linux/ppc64/config.h: -------------------------------------------------------------------------------- 1 | #ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_ 2 | #define THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_ 3 | 4 | /* Define to 1 if the compiler supports __builtin_ctz and friends. */ 5 | #define HAVE_BUILTIN_CTZ 1 6 | 7 | /* Define to 1 if the compiler supports __builtin_expect. */ 8 | #define HAVE_BUILTIN_EXPECT 1 9 | 10 | /* Define to 1 if you have the header file. */ 11 | #define HAVE_BYTESWAP_H 1 12 | 13 | /* Define to 1 if you have a definition for mmap() in . */ 14 | #define HAVE_FUNC_MMAP 1 15 | 16 | /* Define to 1 if you have a definition for sysconf() in . */ 17 | #define HAVE_FUNC_SYSCONF 1 18 | 19 | /* Define to 1 to use the gflags package for command-line parsing. */ 20 | /* #undef HAVE_GFLAGS */ 21 | 22 | /* Define to 1 if you have Google Test. */ 23 | /* #undef HAVE_GTEST */ 24 | 25 | /* Define to 1 if you have the `lzo2' library (-llzo2). */ 26 | /* #undef HAVE_LIBLZO2 */ 27 | 28 | /* Define to 1 if you have the `z' library (-lz). */ 29 | #define HAVE_LIBZ 1 30 | 31 | /* Define to 1 if you have the header file. */ 32 | #define HAVE_STDDEF_H 1 33 | 34 | /* Define to 1 if you have the header file. */ 35 | #define HAVE_STDINT_H 1 36 | 37 | /* Define to 1 if you have the header file. */ 38 | /* #undef HAVE_SYS_ENDIAN_H */ 39 | 40 | /* Define to 1 if you have the header file. */ 41 | #define HAVE_SYS_MMAN_H 1 42 | 43 | /* Define to 1 if you have the header file. */ 44 | #define HAVE_SYS_RESOURCE_H 1 45 | 46 | /* Define to 1 if you have the header file. */ 47 | #define HAVE_SYS_TIME_H 1 48 | 49 | /* Define to 1 if you have the header file. */ 50 | #define HAVE_SYS_UIO_H 1 51 | 52 | /* Define to 1 if you have the header file. */ 53 | #define HAVE_UNISTD_H 1 54 | 55 | /* Define to 1 if you have the header file. */ 56 | /* #undef HAVE_WINDOWS_H */ 57 | 58 | /* Define to 1 if your processor stores words with the most significant byte 59 | first (like Motorola and SPARC, unlike Intel and VAX). */ 60 | #define SNAPPY_IS_BIG_ENDIAN 1 61 | 62 | #endif // THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_ 63 | -------------------------------------------------------------------------------- /deps/snappy/linux/s390x/config.h: -------------------------------------------------------------------------------- 1 | #ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_ 2 | #define THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_ 3 | 4 | /* Define to 1 if the compiler supports __builtin_ctz and friends. */ 5 | #define HAVE_BUILTIN_CTZ 1 6 | 7 | /* Define to 1 if the compiler supports __builtin_expect. */ 8 | #define HAVE_BUILTIN_EXPECT 1 9 | 10 | /* Define to 1 if you have the header file. */ 11 | #define HAVE_BYTESWAP_H 1 12 | 13 | /* Define to 1 if you have a definition for mmap() in . */ 14 | #define HAVE_FUNC_MMAP 1 15 | 16 | /* Define to 1 if you have a definition for sysconf() in . */ 17 | #define HAVE_FUNC_SYSCONF 1 18 | 19 | /* Define to 1 to use the gflags package for command-line parsing. */ 20 | /* #undef HAVE_GFLAGS */ 21 | 22 | /* Define to 1 if you have Google Test. */ 23 | /* #undef HAVE_GTEST */ 24 | 25 | /* Define to 1 if you have the `lzo2' library (-llzo2). */ 26 | /* #undef HAVE_LIBLZO2 */ 27 | 28 | /* Define to 1 if you have the `z' library (-lz). */ 29 | #define HAVE_LIBZ 1 30 | 31 | /* Define to 1 if you have the header file. */ 32 | #define HAVE_STDDEF_H 1 33 | 34 | /* Define to 1 if you have the header file. */ 35 | #define HAVE_STDINT_H 1 36 | 37 | /* Define to 1 if you have the header file. */ 38 | /* #undef HAVE_SYS_ENDIAN_H */ 39 | 40 | /* Define to 1 if you have the header file. */ 41 | #define HAVE_SYS_MMAN_H 1 42 | 43 | /* Define to 1 if you have the header file. */ 44 | #define HAVE_SYS_RESOURCE_H 1 45 | 46 | /* Define to 1 if you have the header file. */ 47 | #define HAVE_SYS_TIME_H 1 48 | 49 | /* Define to 1 if you have the header file. */ 50 | #define HAVE_SYS_UIO_H 1 51 | 52 | /* Define to 1 if you have the header file. */ 53 | #define HAVE_UNISTD_H 1 54 | 55 | /* Define to 1 if you have the header file. */ 56 | /* #undef HAVE_WINDOWS_H */ 57 | 58 | /* Define to 1 if your processor stores words with the most significant byte 59 | first (like Motorola and SPARC, unlike Intel and VAX). */ 60 | #define SNAPPY_IS_BIG_ENDIAN 1 61 | 62 | #endif // THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_ 63 | -------------------------------------------------------------------------------- /deps/snappy/mac/config.h: -------------------------------------------------------------------------------- 1 | #ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_ 2 | #define THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_ 3 | 4 | /* Define to 1 if the compiler supports __builtin_ctz and friends. */ 5 | #define HAVE_BUILTIN_CTZ 1 6 | 7 | /* Define to 1 if the compiler supports __builtin_expect. */ 8 | #define HAVE_BUILTIN_EXPECT 1 9 | 10 | /* Define to 1 if you have the header file. */ 11 | /* #undef HAVE_BYTESWAP_H */ 12 | 13 | /* Define to 1 if you have a definition for mmap() in . */ 14 | #define HAVE_FUNC_MMAP 1 15 | 16 | /* Define to 1 if you have a definition for sysconf() in . */ 17 | #define HAVE_FUNC_SYSCONF 1 18 | 19 | /* Define to 1 to use the gflags package for command-line parsing. */ 20 | /* #undef HAVE_GFLAGS */ 21 | 22 | /* Define to 1 if you have Google Test. */ 23 | /* #undef HAVE_GTEST */ 24 | 25 | /* Define to 1 if you have the `lzo2' library (-llzo2). */ 26 | /* #undef HAVE_LIBLZO2 */ 27 | 28 | /* Define to 1 if you have the `z' library (-lz). */ 29 | #define HAVE_LIBZ 1 30 | 31 | /* Define to 1 if you have the header file. */ 32 | #define HAVE_STDDEF_H 1 33 | 34 | /* Define to 1 if you have the header file. */ 35 | #define HAVE_STDINT_H 1 36 | 37 | /* Define to 1 if you have the header file. */ 38 | /* #undef HAVE_SYS_ENDIAN_H */ 39 | 40 | /* Define to 1 if you have the header file. */ 41 | #define HAVE_SYS_MMAN_H 1 42 | 43 | /* Define to 1 if you have the header file. */ 44 | #define HAVE_SYS_RESOURCE_H 1 45 | 46 | /* Define to 1 if you have the header file. */ 47 | #define HAVE_SYS_TIME_H 1 48 | 49 | /* Define to 1 if you have the header file. */ 50 | #define HAVE_SYS_UIO_H 1 51 | 52 | /* Define to 1 if you have the header file. */ 53 | #define HAVE_UNISTD_H 1 54 | 55 | /* Define to 1 if you have the header file. */ 56 | /* #undef HAVE_WINDOWS_H */ 57 | 58 | /* Define to 1 if your processor stores words with the most significant byte 59 | first (like Motorola and SPARC, unlike Intel and VAX). */ 60 | /* #undef SNAPPY_IS_BIG_ENDIAN */ 61 | 62 | #endif // THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_ 63 | -------------------------------------------------------------------------------- /deps/snappy/solaris/config.h: -------------------------------------------------------------------------------- 1 | #ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_ 2 | #define THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_ 3 | 4 | /* Define to 1 if the compiler supports __builtin_ctz and friends. */ 5 | #define HAVE_BUILTIN_CTZ 1 6 | 7 | /* Define to 1 if the compiler supports __builtin_expect. */ 8 | #define HAVE_BUILTIN_EXPECT 1 9 | 10 | /* Define to 1 if you have the header file. */ 11 | /* #undef HAVE_BYTESWAP_H */ 12 | 13 | /* Define to 1 if you have a definition for mmap() in . */ 14 | #define HAVE_FUNC_MMAP 1 15 | 16 | /* Define to 1 if you have a definition for sysconf() in . */ 17 | #define HAVE_FUNC_SYSCONF 1 18 | 19 | /* Define to 1 to use the gflags package for command-line parsing. */ 20 | /* #undef HAVE_GFLAGS */ 21 | 22 | /* Define to 1 if you have Google Test. */ 23 | /* #undef HAVE_GTEST */ 24 | 25 | /* Define to 1 if you have the `lzo2' library (-llzo2). */ 26 | #define HAVE_LIBLZO2 1 27 | 28 | /* Define to 1 if you have the `z' library (-lz). */ 29 | #define HAVE_LIBZ 1 30 | 31 | /* Define to 1 if you have the header file. */ 32 | #define HAVE_STDDEF_H 1 33 | 34 | /* Define to 1 if you have the header file. */ 35 | #define HAVE_STDINT_H 1 36 | 37 | /* Define to 1 if you have the header file. */ 38 | /* #undef HAVE_SYS_ENDIAN_H */ 39 | 40 | /* Define to 1 if you have the header file. */ 41 | #define HAVE_SYS_MMAN_H 1 42 | 43 | /* Define to 1 if you have the header file. */ 44 | #define HAVE_SYS_RESOURCE_H 1 45 | 46 | /* Define to 1 if you have the header file. */ 47 | #define HAVE_SYS_TIME_H 1 48 | 49 | /* Define to 1 if you have the header file. */ 50 | #define HAVE_SYS_UIO_H 1 51 | 52 | /* Define to 1 if you have the header file. */ 53 | #define HAVE_UNISTD_H 1 54 | 55 | /* Define to 1 if you have the header file. */ 56 | /* #undef HAVE_WINDOWS_H */ 57 | 58 | /* Define to 1 if your processor stores words with the most significant byte 59 | first (like Motorola and SPARC, unlike Intel and VAX). */ 60 | /* #undef SNAPPY_IS_BIG_ENDIAN */ 61 | 62 | #endif // THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_ 63 | -------------------------------------------------------------------------------- /deps/snappy/linux/generic/config.h: -------------------------------------------------------------------------------- 1 | #ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_ 2 | #define THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_ 3 | 4 | /* Define to 1 if the compiler supports __builtin_ctz and friends. */ 5 | #define HAVE_BUILTIN_CTZ 1 6 | 7 | /* Define to 1 if the compiler supports __builtin_expect. */ 8 | #define HAVE_BUILTIN_EXPECT 1 9 | 10 | /* Define to 1 if you have the header file. */ 11 | #define HAVE_BYTESWAP_H 1 12 | 13 | /* Define to 1 if you have a definition for mmap() in . */ 14 | #define HAVE_FUNC_MMAP 1 15 | 16 | /* Define to 1 if you have a definition for sysconf() in . */ 17 | #define HAVE_FUNC_SYSCONF 1 18 | 19 | /* Define to 1 to use the gflags package for command-line parsing. */ 20 | /* #undef HAVE_GFLAGS */ 21 | 22 | /* Define to 1 if you have Google Test. */ 23 | /* #undef HAVE_GTEST */ 24 | 25 | /* Define to 1 if you have the `lzo2' library (-llzo2). */ 26 | /* #undef HAVE_LIBLZO2 */ 27 | 28 | /* Define to 1 if you have the `z' library (-lz). */ 29 | #define HAVE_LIBZ 1 30 | 31 | /* Define to 1 if you have the header file. */ 32 | #define HAVE_STDDEF_H 1 33 | 34 | /* Define to 1 if you have the header file. */ 35 | #define HAVE_STDINT_H 1 36 | 37 | /* Define to 1 if you have the header file. */ 38 | /* #undef HAVE_SYS_ENDIAN_H */ 39 | 40 | /* Define to 1 if you have the header file. */ 41 | #define HAVE_SYS_MMAN_H 1 42 | 43 | /* Define to 1 if you have the header file. */ 44 | #define HAVE_SYS_RESOURCE_H 1 45 | 46 | /* Define to 1 if you have the header file. */ 47 | #define HAVE_SYS_TIME_H 1 48 | 49 | /* Define to 1 if you have the header file. */ 50 | #define HAVE_SYS_UIO_H 1 51 | 52 | /* Define to 1 if you have the header file. */ 53 | #define HAVE_UNISTD_H 1 54 | 55 | /* Define to 1 if you have the header file. */ 56 | /* #undef HAVE_WINDOWS_H */ 57 | 58 | /* Define to 1 if your processor stores words with the most significant byte 59 | first (like Motorola and SPARC, unlike Intel and VAX). */ 60 | /* #undef SNAPPY_IS_BIG_ENDIAN */ 61 | 62 | #endif // THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_ 63 | -------------------------------------------------------------------------------- /deps/snappy/win32/config.h: -------------------------------------------------------------------------------- 1 | #ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_ 2 | #define THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_ 3 | 4 | /* Define to 1 if the compiler supports __builtin_ctz and friends. */ 5 | /* #undef HAVE_BUILTIN_CTZ */ 6 | 7 | /* Define to 1 if the compiler supports __builtin_expect. */ 8 | /* #undef HAVE_BUILTIN_EXPECT */ 9 | 10 | /* Define to 1 if you have the header file. */ 11 | /* #undef HAVE_BYTESWAP_H */ 12 | 13 | /* Define to 1 if you have a definition for mmap() in . */ 14 | /* #undef HAVE_FUNC_MMAP */ 15 | 16 | /* Define to 1 if you have a definition for sysconf() in . */ 17 | /* #undef HAVE_FUNC_SYSCONF */ 18 | 19 | /* Define to 1 to use the gflags package for command-line parsing. */ 20 | /* #undef HAVE_GFLAGS */ 21 | 22 | /* Define to 1 if you have Google Test. */ 23 | /* #undef HAVE_GTEST */ 24 | 25 | /* Define to 1 if you have the `lzo2' library (-llzo2). */ 26 | /* #undef HAVE_LIBLZO2 */ 27 | 28 | /* Define to 1 if you have the `z' library (-lz). */ 29 | /* #undef HAVE_LIBZ */ 30 | 31 | /* Define to 1 if you have the header file. */ 32 | #define HAVE_STDDEF_H 1 33 | 34 | /* Define to 1 if you have the header file. */ 35 | #define HAVE_STDINT_H 1 36 | 37 | /* Define to 1 if you have the header file. */ 38 | /* #undef HAVE_SYS_ENDIAN_H */ 39 | 40 | /* Define to 1 if you have the header file. */ 41 | /* #undef HAVE_SYS_MMAN_H */ 42 | 43 | /* Define to 1 if you have the header file. */ 44 | /* #undef HAVE_SYS_RESOURCE_H */ 45 | 46 | /* Define to 1 if you have the header file. */ 47 | /* #undef HAVE_SYS_TIME_H */ 48 | 49 | /* Define to 1 if you have the header file. */ 50 | /* #undef HAVE_SYS_UIO_H */ 51 | 52 | /* Define to 1 if you have the header file. */ 53 | /* #undef HAVE_UNISTD_H */ 54 | 55 | /* Define to 1 if you have the header file. */ 56 | #define HAVE_WINDOWS_H 1 57 | 58 | /* Define to 1 if your processor stores words with the most significant byte 59 | first (like Motorola and SPARC, unlike Intel and VAX). */ 60 | /* #undef SNAPPY_IS_BIG_ENDIAN */ 61 | 62 | #endif // THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_ 63 | -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.7/cmake/config.h.in: -------------------------------------------------------------------------------- 1 | #ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_ 2 | #define THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_ 3 | 4 | /* Define to 1 if the compiler supports __builtin_ctz and friends. */ 5 | #cmakedefine HAVE_BUILTIN_CTZ 1 6 | 7 | /* Define to 1 if the compiler supports __builtin_expect. */ 8 | #cmakedefine HAVE_BUILTIN_EXPECT 1 9 | 10 | /* Define to 1 if you have the header file. */ 11 | #cmakedefine HAVE_BYTESWAP_H 1 12 | 13 | /* Define to 1 if you have a definition for mmap() in . */ 14 | #cmakedefine HAVE_FUNC_MMAP 1 15 | 16 | /* Define to 1 if you have a definition for sysconf() in . */ 17 | #cmakedefine HAVE_FUNC_SYSCONF 1 18 | 19 | /* Define to 1 to use the gflags package for command-line parsing. */ 20 | #cmakedefine HAVE_GFLAGS 1 21 | 22 | /* Define to 1 if you have Google Test. */ 23 | #cmakedefine HAVE_GTEST 1 24 | 25 | /* Define to 1 if you have the `lzo2' library (-llzo2). */ 26 | #cmakedefine HAVE_LIBLZO2 1 27 | 28 | /* Define to 1 if you have the `z' library (-lz). */ 29 | #cmakedefine HAVE_LIBZ 1 30 | 31 | /* Define to 1 if you have the header file. */ 32 | #cmakedefine HAVE_STDDEF_H 1 33 | 34 | /* Define to 1 if you have the header file. */ 35 | #cmakedefine HAVE_STDINT_H 1 36 | 37 | /* Define to 1 if you have the header file. */ 38 | #cmakedefine HAVE_SYS_ENDIAN_H 1 39 | 40 | /* Define to 1 if you have the header file. */ 41 | #cmakedefine HAVE_SYS_MMAN_H 1 42 | 43 | /* Define to 1 if you have the header file. */ 44 | #cmakedefine HAVE_SYS_RESOURCE_H 1 45 | 46 | /* Define to 1 if you have the header file. */ 47 | #cmakedefine HAVE_SYS_TIME_H 1 48 | 49 | /* Define to 1 if you have the header file. */ 50 | #cmakedefine HAVE_SYS_UIO_H 1 51 | 52 | /* Define to 1 if you have the header file. */ 53 | #cmakedefine HAVE_UNISTD_H 1 54 | 55 | /* Define to 1 if you have the header file. */ 56 | #cmakedefine HAVE_WINDOWS_H 1 57 | 58 | /* Define to 1 if your processor stores words with the most significant byte 59 | first (like Motorola and SPARC, unlike Intel and VAX). */ 60 | #cmakedefine SNAPPY_IS_BIG_ENDIAN 1 61 | 62 | #endif // THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_ 63 | -------------------------------------------------------------------------------- /snappy.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | var binding = require('bindings')('binding'); 3 | var assert = require('assert'); 4 | 5 | /** 6 | * Compress asyncronous. 7 | * If input isn't a string or buffer, automatically convert to buffer by using 8 | * JSON.stringify. 9 | * @param {string|Buffer} input 10 | * @param {(err: Error|null, buffer?: Buffer) => void} callback 11 | */ 12 | exports.compress = function (input, callback) { 13 | if (!(typeof (input) === 'string' || Buffer.isBuffer(input))) { 14 | return callback(new Error('input must be a String or a Buffer')); 15 | } 16 | 17 | binding.compress(input, callback); 18 | }; 19 | 20 | /** 21 | * @param {string|Buffer} input 22 | * @returns {Buffer} 23 | */ 24 | exports.compressSync = function (input) { 25 | assert(typeof (input) === 'string' || Buffer.isBuffer(input), 'input must be a String or a Buffer'); 26 | 27 | return binding.compressSync(input); 28 | }; 29 | 30 | /** 31 | * Asyncronous decide if a buffer is compressed in a correct way. 32 | * 33 | * @type {(buffer: Buffer, callback: (err: Error|null, isValid?: boolean) => void) => void} 34 | */ 35 | exports.isValidCompressed = binding.isValidCompressed; 36 | 37 | /** 38 | * @type {(buffer: Buffer) => boolean} 39 | */ 40 | exports.isValidCompressedSync = binding.isValidCompressedSync; 41 | 42 | /** 43 | * Asyncronous uncompress previously compressed data. 44 | * 45 | * @param {Buffer} compressed 46 | * @param {any} opts 47 | * @param {(err: Error, uncompressed?:(string|Buffer)) => void} callback 48 | */ 49 | exports.uncompress = function (compressed, opts, callback) { 50 | if (!callback) { 51 | callback = opts; 52 | } 53 | 54 | if (!Buffer.isBuffer(compressed)) { 55 | return callback(new Error('input must be a Buffer')); 56 | } 57 | 58 | binding.uncompress(compressed, uncompressOpts(opts), callback); 59 | }; 60 | 61 | /** 62 | * @param {Buffer} compressed 63 | * @param {any} opts 64 | * @return {string|Buffer} 65 | */exports.uncompressSync = function (compressed, opts) { 66 | assert(Buffer.isBuffer(compressed), 'input must be a Buffer'); 67 | 68 | return binding.uncompressSync(compressed, uncompressOpts(opts)); 69 | }; 70 | 71 | /** 72 | * @param {any} opts 73 | */ 74 | function uncompressOpts (opts) { 75 | return (opts && typeof opts.asBuffer === 'boolean') ? opts : {asBuffer: true}; 76 | } 77 | -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.7/COPYING: -------------------------------------------------------------------------------- 1 | Copyright 2011, Google Inc. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above 11 | copyright notice, this list of conditions and the following disclaimer 12 | in the documentation and/or other materials provided with the 13 | distribution. 14 | * Neither the name of Google Inc. nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | === 31 | 32 | Some of the benchmark data in testdata/ is licensed differently: 33 | 34 | - fireworks.jpeg is Copyright 2013 Steinar H. Gunderson, and 35 | is licensed under the Creative Commons Attribution 3.0 license 36 | (CC-BY-3.0). See https://creativecommons.org/licenses/by/3.0/ 37 | for more information. 38 | 39 | - kppkn.gtb is taken from the Gaviota chess tablebase set, and 40 | is licensed under the MIT License. See 41 | https://sites.google.com/site/gaviotachessengine/Home/endgame-tablebases-1 42 | for more information. 43 | 44 | - paper-100k.pdf is an excerpt (bytes 92160 to 194560) from the paper 45 | “Combinatorial Modeling of Chromatin Features Quantitatively Predicts DNA 46 | Replication Timing in _Drosophila_” by Federico Comoglio and Renato Paro, 47 | which is licensed under the CC-BY license. See 48 | http://www.ploscompbiol.org/static/license for more ifnormation. 49 | 50 | - alice29.txt, asyoulik.txt, plrabn12.txt and lcet10.txt are from Project 51 | Gutenberg. The first three have expired copyrights and are in the public 52 | domain; the latter does not have expired copyright, but is still in the 53 | public domain according to the license information 54 | (http://www.gutenberg.org/ebooks/53). 55 | -------------------------------------------------------------------------------- /deps/snappy/mac/snappy-stubs-public.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. All Rights Reserved. 2 | // Author: sesse@google.com (Steinar H. Gunderson) 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Various type stubs for the open-source version of Snappy. 31 | // 32 | // This file cannot include config.h, as it is included from snappy.h, 33 | // which is a public header. Instead, snappy-stubs-public.h is generated by 34 | // from snappy-stubs-public.h.in at configure time. 35 | 36 | #ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 37 | #define THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 38 | 39 | #if 1 // HAVE_STDINT_H 40 | #include 41 | #endif // HAVE_STDDEF_H 42 | 43 | #if 1 // HAVE_STDDEF_H 44 | #include 45 | #endif // HAVE_STDDEF_H 46 | 47 | #if 1 // HAVE_SYS_UIO_H 48 | #include 49 | #endif // HAVE_SYS_UIO_H 50 | 51 | #define SNAPPY_MAJOR 52 | #define SNAPPY_MINOR 53 | #define SNAPPY_PATCHLEVEL 54 | #define SNAPPY_VERSION \ 55 | ((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL) 56 | 57 | #include 58 | 59 | namespace snappy { 60 | 61 | #if 1 // HAVE_STDINT_H 62 | typedef int8_t int8; 63 | typedef uint8_t uint8; 64 | typedef int16_t int16; 65 | typedef uint16_t uint16; 66 | typedef int32_t int32; 67 | typedef uint32_t uint32; 68 | typedef int64_t int64; 69 | typedef uint64_t uint64; 70 | #else 71 | typedef signed char int8; 72 | typedef unsigned char uint8; 73 | typedef short int16; 74 | typedef unsigned short uint16; 75 | typedef int int32; 76 | typedef unsigned int uint32; 77 | typedef long long int64; 78 | typedef unsigned long long uint64; 79 | #endif // HAVE_STDINT_H 80 | 81 | typedef std::string string; 82 | 83 | #if !1 // !HAVE_SYS_UIO_H 84 | // Windows does not have an iovec type, yet the concept is universally useful. 85 | // It is simple to define it ourselves, so we put it inside our own namespace. 86 | struct iovec { 87 | void* iov_base; 88 | size_t iov_len; 89 | }; 90 | #endif // !HAVE_SYS_UIO_H 91 | 92 | } // namespace snappy 93 | 94 | #endif // THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 95 | -------------------------------------------------------------------------------- /deps/snappy/freebsd/snappy-stubs-public.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. All Rights Reserved. 2 | // Author: sesse@google.com (Steinar H. Gunderson) 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Various type stubs for the open-source version of Snappy. 31 | // 32 | // This file cannot include config.h, as it is included from snappy.h, 33 | // which is a public header. Instead, snappy-stubs-public.h is generated by 34 | // from snappy-stubs-public.h.in at configure time. 35 | 36 | #ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 37 | #define THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 38 | 39 | #if 1 // HAVE_STDINT_H 40 | #include 41 | #endif // HAVE_STDDEF_H 42 | 43 | #if 1 // HAVE_STDDEF_H 44 | #include 45 | #endif // HAVE_STDDEF_H 46 | 47 | #if 1 // HAVE_SYS_UIO_H 48 | #include 49 | #endif // HAVE_SYS_UIO_H 50 | 51 | #define SNAPPY_MAJOR 52 | #define SNAPPY_MINOR 53 | #define SNAPPY_PATCHLEVEL 54 | #define SNAPPY_VERSION \ 55 | ((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL) 56 | 57 | #include 58 | 59 | namespace snappy { 60 | 61 | #if 1 // HAVE_STDINT_H 62 | typedef int8_t int8; 63 | typedef uint8_t uint8; 64 | typedef int16_t int16; 65 | typedef uint16_t uint16; 66 | typedef int32_t int32; 67 | typedef uint32_t uint32; 68 | typedef int64_t int64; 69 | typedef uint64_t uint64; 70 | #else 71 | typedef signed char int8; 72 | typedef unsigned char uint8; 73 | typedef short int16; 74 | typedef unsigned short uint16; 75 | typedef int int32; 76 | typedef unsigned int uint32; 77 | typedef long long int64; 78 | typedef unsigned long long uint64; 79 | #endif // HAVE_STDINT_H 80 | 81 | typedef std::string string; 82 | 83 | #if !1 // !HAVE_SYS_UIO_H 84 | // Windows does not have an iovec type, yet the concept is universally useful. 85 | // It is simple to define it ourselves, so we put it inside our own namespace. 86 | struct iovec { 87 | void* iov_base; 88 | size_t iov_len; 89 | }; 90 | #endif // !HAVE_SYS_UIO_H 91 | 92 | } // namespace snappy 93 | 94 | #endif // THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 95 | -------------------------------------------------------------------------------- /deps/snappy/solaris/snappy-stubs-public.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. All Rights Reserved. 2 | // Author: sesse@google.com (Steinar H. Gunderson) 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Various type stubs for the open-source version of Snappy. 31 | // 32 | // This file cannot include config.h, as it is included from snappy.h, 33 | // which is a public header. Instead, snappy-stubs-public.h is generated by 34 | // from snappy-stubs-public.h.in at configure time. 35 | 36 | #ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 37 | #define THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 38 | 39 | #if 1 // HAVE_STDINT_H 40 | #include 41 | #endif // HAVE_STDDEF_H 42 | 43 | #if 1 // HAVE_STDDEF_H 44 | #include 45 | #endif // HAVE_STDDEF_H 46 | 47 | #if 1 // HAVE_SYS_UIO_H 48 | #include 49 | #endif // HAVE_SYS_UIO_H 50 | 51 | #define SNAPPY_MAJOR 52 | #define SNAPPY_MINOR 53 | #define SNAPPY_PATCHLEVEL 54 | #define SNAPPY_VERSION \ 55 | ((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL) 56 | 57 | #include 58 | 59 | namespace snappy { 60 | 61 | #if 1 // HAVE_STDINT_H 62 | typedef int8_t int8; 63 | typedef uint8_t uint8; 64 | typedef int16_t int16; 65 | typedef uint16_t uint16; 66 | typedef int32_t int32; 67 | typedef uint32_t uint32; 68 | typedef int64_t int64; 69 | typedef uint64_t uint64; 70 | #else 71 | typedef signed char int8; 72 | typedef unsigned char uint8; 73 | typedef short int16; 74 | typedef unsigned short uint16; 75 | typedef int int32; 76 | typedef unsigned int uint32; 77 | typedef long long int64; 78 | typedef unsigned long long uint64; 79 | #endif // HAVE_STDINT_H 80 | 81 | typedef std::string string; 82 | 83 | #if !1 // !HAVE_SYS_UIO_H 84 | // Windows does not have an iovec type, yet the concept is universally useful. 85 | // It is simple to define it ourselves, so we put it inside our own namespace. 86 | struct iovec { 87 | void* iov_base; 88 | size_t iov_len; 89 | }; 90 | #endif // !HAVE_SYS_UIO_H 91 | 92 | } // namespace snappy 93 | 94 | #endif // THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 95 | -------------------------------------------------------------------------------- /deps/snappy/win32/snappy-stubs-public.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. All Rights Reserved. 2 | // Author: sesse@google.com (Steinar H. Gunderson) 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Various type stubs for the open-source version of Snappy. 31 | // 32 | // This file cannot include config.h, as it is included from snappy.h, 33 | // which is a public header. Instead, snappy-stubs-public.h is generated by 34 | // from snappy-stubs-public.h.in at configure time. 35 | 36 | #ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 37 | #define THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 38 | 39 | #if 1 // HAVE_STDINT_H 40 | #include 41 | #endif // HAVE_STDDEF_H 42 | 43 | #if 1 // HAVE_STDDEF_H 44 | #include 45 | #endif // HAVE_STDDEF_H 46 | 47 | #if 0 // HAVE_SYS_UIO_H 48 | #include 49 | #endif // HAVE_SYS_UIO_H 50 | 51 | #define SNAPPY_MAJOR 52 | #define SNAPPY_MINOR 53 | #define SNAPPY_PATCHLEVEL 54 | #define SNAPPY_VERSION \ 55 | ((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL) 56 | 57 | #include 58 | 59 | namespace snappy { 60 | 61 | #if 1 // HAVE_STDINT_H 62 | typedef int8_t int8; 63 | typedef uint8_t uint8; 64 | typedef int16_t int16; 65 | typedef uint16_t uint16; 66 | typedef int32_t int32; 67 | typedef uint32_t uint32; 68 | typedef int64_t int64; 69 | typedef uint64_t uint64; 70 | #else 71 | typedef signed char int8; 72 | typedef unsigned char uint8; 73 | typedef short int16; 74 | typedef unsigned short uint16; 75 | typedef int int32; 76 | typedef unsigned int uint32; 77 | typedef long long int64; 78 | typedef unsigned long long uint64; 79 | #endif // HAVE_STDINT_H 80 | 81 | typedef std::string string; 82 | 83 | #if !0 // !HAVE_SYS_UIO_H 84 | // Windows does not have an iovec type, yet the concept is universally useful. 85 | // It is simple to define it ourselves, so we put it inside our own namespace. 86 | struct iovec { 87 | void* iov_base; 88 | size_t iov_len; 89 | }; 90 | #endif // !HAVE_SYS_UIO_H 91 | 92 | } // namespace snappy 93 | 94 | #endif // THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 95 | -------------------------------------------------------------------------------- /deps/snappy/linux/generic/snappy-stubs-public.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. All Rights Reserved. 2 | // Author: sesse@google.com (Steinar H. Gunderson) 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Various type stubs for the open-source version of Snappy. 31 | // 32 | // This file cannot include config.h, as it is included from snappy.h, 33 | // which is a public header. Instead, snappy-stubs-public.h is generated by 34 | // from snappy-stubs-public.h.in at configure time. 35 | 36 | #ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 37 | #define THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 38 | 39 | #if 1 // HAVE_STDINT_H 40 | #include 41 | #endif // HAVE_STDDEF_H 42 | 43 | #if 1 // HAVE_STDDEF_H 44 | #include 45 | #endif // HAVE_STDDEF_H 46 | 47 | #if 1 // HAVE_SYS_UIO_H 48 | #include 49 | #endif // HAVE_SYS_UIO_H 50 | 51 | #define SNAPPY_MAJOR 52 | #define SNAPPY_MINOR 53 | #define SNAPPY_PATCHLEVEL 54 | #define SNAPPY_VERSION \ 55 | ((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL) 56 | 57 | #include 58 | 59 | namespace snappy { 60 | 61 | #if 1 // HAVE_STDINT_H 62 | typedef int8_t int8; 63 | typedef uint8_t uint8; 64 | typedef int16_t int16; 65 | typedef uint16_t uint16; 66 | typedef int32_t int32; 67 | typedef uint32_t uint32; 68 | typedef int64_t int64; 69 | typedef uint64_t uint64; 70 | #else 71 | typedef signed char int8; 72 | typedef unsigned char uint8; 73 | typedef short int16; 74 | typedef unsigned short uint16; 75 | typedef int int32; 76 | typedef unsigned int uint32; 77 | typedef long long int64; 78 | typedef unsigned long long uint64; 79 | #endif // HAVE_STDINT_H 80 | 81 | typedef std::string string; 82 | 83 | #if !1 // !HAVE_SYS_UIO_H 84 | // Windows does not have an iovec type, yet the concept is universally useful. 85 | // It is simple to define it ourselves, so we put it inside our own namespace. 86 | struct iovec { 87 | void* iov_base; 88 | size_t iov_len; 89 | }; 90 | #endif // !HAVE_SYS_UIO_H 91 | 92 | } // namespace snappy 93 | 94 | #endif // THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 95 | -------------------------------------------------------------------------------- /deps/snappy/linux/ppc64/snappy-stubs-public.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. All Rights Reserved. 2 | // Author: sesse@google.com (Steinar H. Gunderson) 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Various type stubs for the open-source version of Snappy. 31 | // 32 | // This file cannot include config.h, as it is included from snappy.h, 33 | // which is a public header. Instead, snappy-stubs-public.h is generated by 34 | // from snappy-stubs-public.h.in at configure time. 35 | 36 | #ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 37 | #define THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 38 | 39 | #if 1 // HAVE_STDINT_H 40 | #include 41 | #endif // HAVE_STDDEF_H 42 | 43 | #if 1 // HAVE_STDDEF_H 44 | #include 45 | #endif // HAVE_STDDEF_H 46 | 47 | #if 1 // HAVE_SYS_UIO_H 48 | #include 49 | #endif // HAVE_SYS_UIO_H 50 | 51 | #define SNAPPY_MAJOR 52 | #define SNAPPY_MINOR 53 | #define SNAPPY_PATCHLEVEL 54 | #define SNAPPY_VERSION \ 55 | ((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL) 56 | 57 | #include 58 | 59 | namespace snappy { 60 | 61 | #if 1 // HAVE_STDINT_H 62 | typedef int8_t int8; 63 | typedef uint8_t uint8; 64 | typedef int16_t int16; 65 | typedef uint16_t uint16; 66 | typedef int32_t int32; 67 | typedef uint32_t uint32; 68 | typedef int64_t int64; 69 | typedef uint64_t uint64; 70 | #else 71 | typedef signed char int8; 72 | typedef unsigned char uint8; 73 | typedef short int16; 74 | typedef unsigned short uint16; 75 | typedef int int32; 76 | typedef unsigned int uint32; 77 | typedef long long int64; 78 | typedef unsigned long long uint64; 79 | #endif // HAVE_STDINT_H 80 | 81 | typedef std::string string; 82 | 83 | #if !1 // !HAVE_SYS_UIO_H 84 | // Windows does not have an iovec type, yet the concept is universally useful. 85 | // It is simple to define it ourselves, so we put it inside our own namespace. 86 | struct iovec { 87 | void* iov_base; 88 | size_t iov_len; 89 | }; 90 | #endif // !HAVE_SYS_UIO_H 91 | 92 | } // namespace snappy 93 | 94 | #endif // THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 95 | -------------------------------------------------------------------------------- /deps/snappy/linux/ppc64le/snappy-stubs-public.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. All Rights Reserved. 2 | // Author: sesse@google.com (Steinar H. Gunderson) 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Various type stubs for the open-source version of Snappy. 31 | // 32 | // This file cannot include config.h, as it is included from snappy.h, 33 | // which is a public header. Instead, snappy-stubs-public.h is generated by 34 | // from snappy-stubs-public.h.in at configure time. 35 | 36 | #ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 37 | #define THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 38 | 39 | #if 1 // HAVE_STDINT_H 40 | #include 41 | #endif // HAVE_STDDEF_H 42 | 43 | #if 1 // HAVE_STDDEF_H 44 | #include 45 | #endif // HAVE_STDDEF_H 46 | 47 | #if 1 // HAVE_SYS_UIO_H 48 | #include 49 | #endif // HAVE_SYS_UIO_H 50 | 51 | #define SNAPPY_MAJOR 52 | #define SNAPPY_MINOR 53 | #define SNAPPY_PATCHLEVEL 54 | #define SNAPPY_VERSION \ 55 | ((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL) 56 | 57 | #include 58 | 59 | namespace snappy { 60 | 61 | #if 1 // HAVE_STDINT_H 62 | typedef int8_t int8; 63 | typedef uint8_t uint8; 64 | typedef int16_t int16; 65 | typedef uint16_t uint16; 66 | typedef int32_t int32; 67 | typedef uint32_t uint32; 68 | typedef int64_t int64; 69 | typedef uint64_t uint64; 70 | #else 71 | typedef signed char int8; 72 | typedef unsigned char uint8; 73 | typedef short int16; 74 | typedef unsigned short uint16; 75 | typedef int int32; 76 | typedef unsigned int uint32; 77 | typedef long long int64; 78 | typedef unsigned long long uint64; 79 | #endif // HAVE_STDINT_H 80 | 81 | typedef std::string string; 82 | 83 | #if !1 // !HAVE_SYS_UIO_H 84 | // Windows does not have an iovec type, yet the concept is universally useful. 85 | // It is simple to define it ourselves, so we put it inside our own namespace. 86 | struct iovec { 87 | void* iov_base; 88 | size_t iov_len; 89 | }; 90 | #endif // !HAVE_SYS_UIO_H 91 | 92 | } // namespace snappy 93 | 94 | #endif // THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 95 | -------------------------------------------------------------------------------- /deps/snappy/linux/s390x/snappy-stubs-public.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. All Rights Reserved. 2 | // Author: sesse@google.com (Steinar H. Gunderson) 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Various type stubs for the open-source version of Snappy. 31 | // 32 | // This file cannot include config.h, as it is included from snappy.h, 33 | // which is a public header. Instead, snappy-stubs-public.h is generated by 34 | // from snappy-stubs-public.h.in at configure time. 35 | 36 | #ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 37 | #define THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 38 | 39 | #if 1 // HAVE_STDINT_H 40 | #include 41 | #endif // HAVE_STDDEF_H 42 | 43 | #if 1 // HAVE_STDDEF_H 44 | #include 45 | #endif // HAVE_STDDEF_H 46 | 47 | #if 1 // HAVE_SYS_UIO_H 48 | #include 49 | #endif // HAVE_SYS_UIO_H 50 | 51 | #define SNAPPY_MAJOR 52 | #define SNAPPY_MINOR 53 | #define SNAPPY_PATCHLEVEL 54 | #define SNAPPY_VERSION \ 55 | ((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL) 56 | 57 | #include 58 | 59 | namespace snappy { 60 | 61 | #if 1 // HAVE_STDINT_H 62 | typedef int8_t int8; 63 | typedef uint8_t uint8; 64 | typedef int16_t int16; 65 | typedef uint16_t uint16; 66 | typedef int32_t int32; 67 | typedef uint32_t uint32; 68 | typedef int64_t int64; 69 | typedef uint64_t uint64; 70 | #else 71 | typedef signed char int8; 72 | typedef unsigned char uint8; 73 | typedef short int16; 74 | typedef unsigned short uint16; 75 | typedef int int32; 76 | typedef unsigned int uint32; 77 | typedef long long int64; 78 | typedef unsigned long long uint64; 79 | #endif // HAVE_STDINT_H 80 | 81 | typedef std::string string; 82 | 83 | #if !1 // !HAVE_SYS_UIO_H 84 | // Windows does not have an iovec type, yet the concept is universally useful. 85 | // It is simple to define it ourselves, so we put it inside our own namespace. 86 | struct iovec { 87 | void* iov_base; 88 | size_t iov_len; 89 | }; 90 | #endif // !HAVE_SYS_UIO_H 91 | 92 | } // namespace snappy 93 | 94 | #endif // THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 95 | -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.7/snappy-stubs-public.h.in: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. All Rights Reserved. 2 | // Author: sesse@google.com (Steinar H. Gunderson) 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Various type stubs for the open-source version of Snappy. 31 | // 32 | // This file cannot include config.h, as it is included from snappy.h, 33 | // which is a public header. Instead, snappy-stubs-public.h is generated by 34 | // from snappy-stubs-public.h.in at configure time. 35 | 36 | #ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 37 | #define THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 38 | 39 | #if ${HAVE_STDINT_H_01} // HAVE_STDINT_H 40 | #include 41 | #endif // HAVE_STDDEF_H 42 | 43 | #if ${HAVE_STDDEF_H_01} // HAVE_STDDEF_H 44 | #include 45 | #endif // HAVE_STDDEF_H 46 | 47 | #if ${HAVE_SYS_UIO_H_01} // HAVE_SYS_UIO_H 48 | #include 49 | #endif // HAVE_SYS_UIO_H 50 | 51 | #define SNAPPY_MAJOR ${SNAPPY_MAJOR} 52 | #define SNAPPY_MINOR ${SNAPPY_MINOR} 53 | #define SNAPPY_PATCHLEVEL ${SNAPPY_PATCHLEVEL} 54 | #define SNAPPY_VERSION \ 55 | ((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL) 56 | 57 | #include 58 | 59 | namespace snappy { 60 | 61 | #if ${HAVE_STDINT_H_01} // HAVE_STDINT_H 62 | typedef int8_t int8; 63 | typedef uint8_t uint8; 64 | typedef int16_t int16; 65 | typedef uint16_t uint16; 66 | typedef int32_t int32; 67 | typedef uint32_t uint32; 68 | typedef int64_t int64; 69 | typedef uint64_t uint64; 70 | #else 71 | typedef signed char int8; 72 | typedef unsigned char uint8; 73 | typedef short int16; 74 | typedef unsigned short uint16; 75 | typedef int int32; 76 | typedef unsigned int uint32; 77 | typedef long long int64; 78 | typedef unsigned long long uint64; 79 | #endif // HAVE_STDINT_H 80 | 81 | typedef std::string string; 82 | 83 | #if !${HAVE_SYS_UIO_H_01} // !HAVE_SYS_UIO_H 84 | // Windows does not have an iovec type, yet the concept is universally useful. 85 | // It is simple to define it ourselves, so we put it inside our own namespace. 86 | struct iovec { 87 | void* iov_base; 88 | size_t iov_len; 89 | }; 90 | #endif // !HAVE_SYS_UIO_H 91 | 92 | } // namespace snappy 93 | 94 | #endif // THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ 95 | -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.7/snappy-sinksource.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. All Rights Reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of Google Inc. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #include 30 | 31 | #include "snappy-sinksource.h" 32 | 33 | namespace snappy { 34 | 35 | Source::~Source() { } 36 | 37 | Sink::~Sink() { } 38 | 39 | char* Sink::GetAppendBuffer(size_t length, char* scratch) { 40 | return scratch; 41 | } 42 | 43 | char* Sink::GetAppendBufferVariable( 44 | size_t min_size, size_t desired_size_hint, char* scratch, 45 | size_t scratch_size, size_t* allocated_size) { 46 | *allocated_size = scratch_size; 47 | return scratch; 48 | } 49 | 50 | void Sink::AppendAndTakeOwnership( 51 | char* bytes, size_t n, 52 | void (*deleter)(void*, const char*, size_t), 53 | void *deleter_arg) { 54 | Append(bytes, n); 55 | (*deleter)(deleter_arg, bytes, n); 56 | } 57 | 58 | ByteArraySource::~ByteArraySource() { } 59 | 60 | size_t ByteArraySource::Available() const { return left_; } 61 | 62 | const char* ByteArraySource::Peek(size_t* len) { 63 | *len = left_; 64 | return ptr_; 65 | } 66 | 67 | void ByteArraySource::Skip(size_t n) { 68 | left_ -= n; 69 | ptr_ += n; 70 | } 71 | 72 | UncheckedByteArraySink::~UncheckedByteArraySink() { } 73 | 74 | void UncheckedByteArraySink::Append(const char* data, size_t n) { 75 | // Do no copying if the caller filled in the result of GetAppendBuffer() 76 | if (data != dest_) { 77 | memcpy(dest_, data, n); 78 | } 79 | dest_ += n; 80 | } 81 | 82 | char* UncheckedByteArraySink::GetAppendBuffer(size_t len, char* scratch) { 83 | return dest_; 84 | } 85 | 86 | void UncheckedByteArraySink::AppendAndTakeOwnership( 87 | char* data, size_t n, 88 | void (*deleter)(void*, const char*, size_t), 89 | void *deleter_arg) { 90 | if (data != dest_) { 91 | memcpy(dest_, data, n); 92 | (*deleter)(deleter_arg, data, n); 93 | } 94 | dest_ += n; 95 | } 96 | 97 | char* UncheckedByteArraySink::GetAppendBufferVariable( 98 | size_t min_size, size_t desired_size_hint, char* scratch, 99 | size_t scratch_size, size_t* allocated_size) { 100 | *allocated_size = desired_size_hint; 101 | return dest_; 102 | } 103 | 104 | } // namespace snappy 105 | -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.7/snappy-c.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Martin Gieseking . 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of Google Inc. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #include "snappy.h" 30 | #include "snappy-c.h" 31 | 32 | extern "C" { 33 | 34 | snappy_status snappy_compress(const char* input, 35 | size_t input_length, 36 | char* compressed, 37 | size_t *compressed_length) { 38 | if (*compressed_length < snappy_max_compressed_length(input_length)) { 39 | return SNAPPY_BUFFER_TOO_SMALL; 40 | } 41 | snappy::RawCompress(input, input_length, compressed, compressed_length); 42 | return SNAPPY_OK; 43 | } 44 | 45 | snappy_status snappy_uncompress(const char* compressed, 46 | size_t compressed_length, 47 | char* uncompressed, 48 | size_t* uncompressed_length) { 49 | size_t real_uncompressed_length; 50 | if (!snappy::GetUncompressedLength(compressed, 51 | compressed_length, 52 | &real_uncompressed_length)) { 53 | return SNAPPY_INVALID_INPUT; 54 | } 55 | if (*uncompressed_length < real_uncompressed_length) { 56 | return SNAPPY_BUFFER_TOO_SMALL; 57 | } 58 | if (!snappy::RawUncompress(compressed, compressed_length, uncompressed)) { 59 | return SNAPPY_INVALID_INPUT; 60 | } 61 | *uncompressed_length = real_uncompressed_length; 62 | return SNAPPY_OK; 63 | } 64 | 65 | size_t snappy_max_compressed_length(size_t source_length) { 66 | return snappy::MaxCompressedLength(source_length); 67 | } 68 | 69 | snappy_status snappy_uncompressed_length(const char *compressed, 70 | size_t compressed_length, 71 | size_t *result) { 72 | if (snappy::GetUncompressedLength(compressed, 73 | compressed_length, 74 | result)) { 75 | return SNAPPY_OK; 76 | } else { 77 | return SNAPPY_INVALID_INPUT; 78 | } 79 | } 80 | 81 | snappy_status snappy_validate_compressed_buffer(const char *compressed, 82 | size_t compressed_length) { 83 | if (snappy::IsValidCompressedBuffer(compressed, compressed_length)) { 84 | return SNAPPY_OK; 85 | } else { 86 | return SNAPPY_INVALID_INPUT; 87 | } 88 | } 89 | 90 | } // extern "C" 91 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import test from 'ava'; 4 | import snappy from './snappy'; 5 | import Promise from 'bluebird'; 6 | 7 | const inputString = 'beep boop, hello world. OMG OMG OMG'; 8 | const inputBuffer = Buffer.from(inputString); 9 | const compress = Promise.promisify(snappy.compress); 10 | const isValidCompressed = Promise.promisify(snappy.isValidCompressed); 11 | const uncompress = Promise.promisify(snappy.uncompress); 12 | const {compressSync, isValidCompressedSync, uncompressSync} = snappy; 13 | 14 | test('compress() string', function * (t) { 15 | const buffer = yield compress(inputString); 16 | t.truthy(Buffer.isBuffer(buffer), 'should return a Buffer'); 17 | }); 18 | 19 | test('compress() buffer', function * (t) { 20 | const buffer = yield compress(inputBuffer); 21 | t.truthy(Buffer.isBuffer(buffer), 'should return a Buffer'); 22 | }); 23 | 24 | test('compress() bad input', function * (t) { 25 | yield t.throws(compress(123), 'input must be a String or a Buffer'); 26 | }); 27 | 28 | test('compressSync() string', function * (t) { 29 | const buffer = compressSync(inputString); 30 | t.truthy(Buffer.isBuffer(buffer), 'should return a Buffer'); 31 | }); 32 | 33 | test('compressSync() buffer', function * (t) { 34 | const buffer = compressSync(inputBuffer); 35 | t.truthy(Buffer.isBuffer(buffer), 'should return a Buffer'); 36 | }); 37 | 38 | test('isValidCompressed() on valid data', function * (t) { 39 | const compressed = yield compress(inputBuffer); 40 | const isCompressed = yield isValidCompressed(compressed); 41 | t.truthy(isCompressed); 42 | }); 43 | 44 | test('isValidCompressed() on invalid data', function * (t) { 45 | const isCompressed = yield isValidCompressed(Buffer.from('beep boop')); 46 | t.falsy(isCompressed); 47 | }); 48 | 49 | test('isValidCompressedSync() on valid data', function * (t) { 50 | const compressed = yield compress(inputBuffer); 51 | const isCompressed = isValidCompressedSync(compressed); 52 | t.truthy(isCompressed); 53 | }); 54 | 55 | test('isValidCompressedSync() on invalid data', function * (t) { 56 | const isCompressed = isValidCompressedSync(Buffer.from('beep boop')); 57 | t.falsy(isCompressed); 58 | }); 59 | 60 | test('uncompress() defaults to Buffer', function * (t) { 61 | const compressed = yield compress(inputBuffer); 62 | const buffer = yield uncompress(compressed); 63 | t.deepEqual(buffer, inputBuffer); 64 | }); 65 | 66 | test('uncompress() returning a Buffer', function * (t) { 67 | const compressed = yield compress(inputBuffer); 68 | const buffer = yield uncompress(compressed, { asBuffer: true }); 69 | t.deepEqual(buffer, inputBuffer); 70 | }); 71 | 72 | test('uncompress() returning a String', function * (t) { 73 | const compressed = yield compress(inputBuffer); 74 | const string = yield uncompress(compressed, { asBuffer: false }); 75 | t.deepEqual(string, inputString); 76 | }); 77 | 78 | test('uncompress() does not change opts', function * (t) { 79 | const compressed = yield compress(inputBuffer); 80 | const opts = {}; 81 | yield uncompress(compressed, opts); 82 | t.deepEqual(opts, {}); 83 | }); 84 | 85 | test('uncompress() on bad input', function * (t) { 86 | yield t.throws(uncompress(Buffer.from('beep boop OMG OMG OMG'), 'Invalid input')); 87 | }); 88 | 89 | test('uncompress() on not a Buffer', function * (t) { 90 | yield t.throws(uncompress('beep boop OMG OMG OMG', 'input must be a Buffer')); 91 | }); 92 | 93 | test('uncompressSync() defaults to Buffer', function * (t) { 94 | const compressed = yield compress(inputBuffer); 95 | const buffer = uncompressSync(compressed); 96 | t.deepEqual(buffer, inputBuffer); 97 | }); 98 | 99 | test('uncompressSync() returning a Buffer', function * (t) { 100 | const compressed = yield compress(inputBuffer); 101 | const buffer = uncompressSync(compressed, { asBuffer: true }); 102 | t.deepEqual(buffer, inputBuffer); 103 | }); 104 | 105 | test('uncompressSync() returning a String', function * (t) { 106 | const compressed = yield compress(inputBuffer); 107 | const string = uncompressSync(compressed, { asBuffer: false }); 108 | t.deepEqual(string, inputString); 109 | }); 110 | 111 | test('uncompress() does not change opts', function * (t) { 112 | const compressed = yield compress(inputBuffer); 113 | const opts = {}; 114 | uncompressSync(compressed, opts); 115 | t.deepEqual(opts, {}); 116 | }); 117 | 118 | test('uncompressSync() on bad input', function * (t) { 119 | t.throws(function () { 120 | uncompressSync(Buffer.from('beep boop OMG OMG OMG')); 121 | }, 'Invalid input'); 122 | }); 123 | -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.7/format_description.txt: -------------------------------------------------------------------------------- 1 | Snappy compressed format description 2 | Last revised: 2011-10-05 3 | 4 | 5 | This is not a formal specification, but should suffice to explain most 6 | relevant parts of how the Snappy format works. It is originally based on 7 | text by Zeev Tarantov. 8 | 9 | Snappy is a LZ77-type compressor with a fixed, byte-oriented encoding. 10 | There is no entropy encoder backend nor framing layer -- the latter is 11 | assumed to be handled by other parts of the system. 12 | 13 | This document only describes the format, not how the Snappy compressor nor 14 | decompressor actually works. The correctness of the decompressor should not 15 | depend on implementation details of the compressor, and vice versa. 16 | 17 | 18 | 1. Preamble 19 | 20 | The stream starts with the uncompressed length (up to a maximum of 2^32 - 1), 21 | stored as a little-endian varint. Varints consist of a series of bytes, 22 | where the lower 7 bits are data and the upper bit is set iff there are 23 | more bytes to be read. In other words, an uncompressed length of 64 would 24 | be stored as 0x40, and an uncompressed length of 2097150 (0x1FFFFE) 25 | would be stored as 0xFE 0xFF 0x7F. 26 | 27 | 28 | 2. The compressed stream itself 29 | 30 | There are two types of elements in a Snappy stream: Literals and 31 | copies (backreferences). There is no restriction on the order of elements, 32 | except that the stream naturally cannot start with a copy. (Having 33 | two literals in a row is never optimal from a compression point of 34 | view, but nevertheless fully permitted.) Each element starts with a tag byte, 35 | and the lower two bits of this tag byte signal what type of element will 36 | follow: 37 | 38 | 00: Literal 39 | 01: Copy with 1-byte offset 40 | 10: Copy with 2-byte offset 41 | 11: Copy with 4-byte offset 42 | 43 | The interpretation of the upper six bits are element-dependent. 44 | 45 | 46 | 2.1. Literals (00) 47 | 48 | Literals are uncompressed data stored directly in the byte stream. 49 | The literal length is stored differently depending on the length 50 | of the literal: 51 | 52 | - For literals up to and including 60 bytes in length, the upper 53 | six bits of the tag byte contain (len-1). The literal follows 54 | immediately thereafter in the bytestream. 55 | - For longer literals, the (len-1) value is stored after the tag byte, 56 | little-endian. The upper six bits of the tag byte describe how 57 | many bytes are used for the length; 60, 61, 62 or 63 for 58 | 1-4 bytes, respectively. The literal itself follows after the 59 | length. 60 | 61 | 62 | 2.2. Copies 63 | 64 | Copies are references back into previous decompressed data, telling 65 | the decompressor to reuse data it has previously decoded. 66 | They encode two values: The _offset_, saying how many bytes back 67 | from the current position to read, and the _length_, how many bytes 68 | to copy. Offsets of zero can be encoded, but are not legal; 69 | similarly, it is possible to encode backreferences that would 70 | go past the end of the block (offset > current decompressed position), 71 | which is also nonsensical and thus not allowed. 72 | 73 | As in most LZ77-based compressors, the length can be larger than the offset, 74 | yielding a form of run-length encoding (RLE). For instance, 75 | "xababab" could be encoded as 76 | 77 | 78 | 79 | Note that since the current Snappy compressor works in 32 kB 80 | blocks and does not do matching across blocks, it will never produce 81 | a bitstream with offsets larger than about 32768. However, the 82 | decompressor should not rely on this, as it may change in the future. 83 | 84 | There are several different kinds of copy elements, depending on 85 | the amount of bytes to be copied (length), and how far back the 86 | data to be copied is (offset). 87 | 88 | 89 | 2.2.1. Copy with 1-byte offset (01) 90 | 91 | These elements can encode lengths between [4..11] bytes and offsets 92 | between [0..2047] bytes. (len-4) occupies three bits and is stored 93 | in bits [2..4] of the tag byte. The offset occupies 11 bits, of which the 94 | upper three are stored in the upper three bits ([5..7]) of the tag byte, 95 | and the lower eight are stored in a byte following the tag byte. 96 | 97 | 98 | 2.2.2. Copy with 2-byte offset (10) 99 | 100 | These elements can encode lengths between [1..64] and offsets from 101 | [0..65535]. (len-1) occupies six bits and is stored in the upper 102 | six bits ([2..7]) of the tag byte. The offset is stored as a 103 | little-endian 16-bit integer in the two bytes following the tag byte. 104 | 105 | 106 | 2.2.3. Copy with 4-byte offset (11) 107 | 108 | These are like the copies with 2-byte offsets (see previous subsection), 109 | except that the offset is stored as a 32-bit integer instead of a 110 | 16-bit integer (and thus will occupy four bytes). 111 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # snappy [![Linux Status](https://img.shields.io/travis/kesla/node-snappy.svg?label=linux)](https://travis-ci.org/kesla/node-snappy) 2 | [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fkesla%2Fnode-snappy.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fkesla%2Fnode-snappy?ref=badge_shield) 3 | 4 | Nodejs bindings to the [snappy](https://github.com/google/snappy) compression library 5 | 6 | [![NPM](https://nodei.co/npm/snappy.png?downloads&stars)](https://nodei.co/npm/snappy/) 7 | 8 | [![NPM](https://nodei.co/npm-dl/snappy.png)](https://nodei.co/npm/snappy/) 9 | 10 | 11 | ## Installation 12 | 13 | ```bash 14 | npm install snappy 15 | ``` 16 | 17 | ## Example 18 | 19 | ### Input 20 | 21 | ```javascript 22 | var snappy = require('snappy') 23 | 24 | snappy.compress('beep boop', function (err, compressed) { 25 | console.log('compressed is a Buffer', compressed) 26 | // return it as a string 27 | snappy.uncompress(compressed, { asBuffer: false }, function (err, original) { 28 | console.log('the original String', original) 29 | }) 30 | }) 31 | ``` 32 | 33 | ### Output 34 | 35 | ```bash 36 | compressed is a Buffer 37 | the original String beep boop 38 | ``` 39 | 40 | ## API 41 | 42 | ### snappy.compress(input, callback) 43 | 44 | Compress `input`, which can be a `Buffer` or a `String`. 45 | 46 | The `callback` function will be called with a single `error` if the operation failed for any reason. If successful the first argument will be `null` and the second argument will be the `value` as a ``Buffer`. 47 | 48 | ### snappy.compressSync(input) 49 | 50 | The synchronous version of `snappy.compress`, returns the compressed value. 51 | 52 | ### snappy.uncompress(compressed, [options,] callback) 53 | 54 | Uncompress `compressed` and call `callback` with `err` and `decompressed`. 55 | 56 | #### `options` 57 | 58 | * `'asBuffer'` *(boolean, default: `true`)*: Used to determine whether to return the `value` of the entry as a `String` or a Node.js `Buffer` object. Note that converting from a `Buffer` to a `String` incurs a cost so if you need a `String` (and the `value` can legitimately become a UFT8 string) then you should fetch it as one with `asBuffer: true` and you'll avoid this conversion cost. 59 | 60 | The `callback` function will be called with a single `error` if the operation failed for any reason. If successful the first argument will be `null` and the second argument will be the `value` as a `String` or `Buffer` depending on the `asBuffer` option. 61 | 62 | ### snappy.uncompressSync(compressed, [options]) 63 | 64 | The synchronous version of `snappy.uncompress`, returns the uncompressed value. 65 | 66 | ### snappy.isValidCompressed(input, callback) 67 | 68 | Check is input is a valid compressed `Buffer`. 69 | 70 | The `callback` function will be called with a single `error` if the operation failed for any reason and the second argument will be `true` if input is a valid snappy compressed Buffer, `false` otherwise. 71 | 72 | ### snappy.isValidCompressedSync(input) 73 | 74 | The synchronous version of `snappy.isValidCompressed`, returns a boolean indicating if input was correctly compressed or not. 75 | 76 | ### stream 77 | 78 | For a streaming interface to snappy, please take a look at [snappy-stream](https://www.npmjs.org/package/snappy-stream) 79 | 80 | ## [Benchmark](benchmark) 81 | 82 | This is the result I'm seeing on my laptop (Macbook Air from 2012) running `node benchmark` 83 | 84 | ```bash 85 | snappy.compress() x 479 ops/sec ±0.99% (80 runs sampled) 86 | zlib.gzip() x 289 ops/sec ±1.66% (86 runs sampled) 87 | snappy.uncompress() x 652 ops/sec ±0.86% (43 runs sampled) 88 | zlib.gunzip() x 559 ops/sec ±1.65% (64 runs sampled) 89 | ``` 90 | 91 | ## License 92 | 93 | Copyright (c) 2011 - 2015 David Björklund & contributors 94 | 95 | Permission is hereby granted, free of charge, to any person obtaining a copy 96 | of this software and associated documentation files (the "Software"), to deal 97 | in the Software without restriction, including without limitation the rights 98 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 99 | copies of the Software, and to permit persons to whom the Software is 100 | furnished to do so, subject to the following conditions: 101 | 102 | The above copyright notice and this permission notice shall be included in 103 | all copies or substantial portions of the Software. 104 | 105 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 106 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 107 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 108 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 109 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 110 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 111 | THE SOFTWARE. 112 | 113 | 114 | [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fkesla%2Fnode-snappy.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fkesla%2Fnode-snappy?ref=badge_large) -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.7/framing_format.txt: -------------------------------------------------------------------------------- 1 | Snappy framing format description 2 | Last revised: 2013-10-25 3 | 4 | This format decribes a framing format for Snappy, allowing compressing to 5 | files or streams that can then more easily be decompressed without having 6 | to hold the entire stream in memory. It also provides data checksums to 7 | help verify integrity. It does not provide metadata checksums, so it does 8 | not protect against e.g. all forms of truncations. 9 | 10 | Implementation of the framing format is optional for Snappy compressors and 11 | decompressor; it is not part of the Snappy core specification. 12 | 13 | 14 | 1. General structure 15 | 16 | The file consists solely of chunks, lying back-to-back with no padding 17 | in between. Each chunk consists first a single byte of chunk identifier, 18 | then a three-byte little-endian length of the chunk in bytes (from 0 to 19 | 16777215, inclusive), and then the data if any. The four bytes of chunk 20 | header is not counted in the data length. 21 | 22 | The different chunk types are listed below. The first chunk must always 23 | be the stream identifier chunk (see section 4.1, below). The stream 24 | ends when the file ends -- there is no explicit end-of-file marker. 25 | 26 | 27 | 2. File type identification 28 | 29 | The following identifiers for this format are recommended where appropriate. 30 | However, note that none have been registered officially, so this is only to 31 | be taken as a guideline. We use "Snappy framed" to distinguish between this 32 | format and raw Snappy data. 33 | 34 | File extension: .sz 35 | MIME type: application/x-snappy-framed 36 | HTTP Content-Encoding: x-snappy-framed 37 | 38 | 39 | 3. Checksum format 40 | 41 | Some chunks have data protected by a checksum (the ones that do will say so 42 | explicitly). The checksums are always masked CRC-32Cs. 43 | 44 | A description of CRC-32C can be found in RFC 3720, section 12.1, with 45 | examples in section B.4. 46 | 47 | Checksums are not stored directly, but masked, as checksumming data and 48 | then its own checksum can be problematic. The masking is the same as used 49 | in Apache Hadoop: Rotate the checksum by 15 bits, then add the constant 50 | 0xa282ead8 (using wraparound as normal for unsigned integers). This is 51 | equivalent to the following C code: 52 | 53 | uint32_t mask_checksum(uint32_t x) { 54 | return ((x >> 15) | (x << 17)) + 0xa282ead8; 55 | } 56 | 57 | Note that the masking is reversible. 58 | 59 | The checksum is always stored as a four bytes long integer, in little-endian. 60 | 61 | 62 | 4. Chunk types 63 | 64 | The currently supported chunk types are described below. The list may 65 | be extended in the future. 66 | 67 | 68 | 4.1. Stream identifier (chunk type 0xff) 69 | 70 | The stream identifier is always the first element in the stream. 71 | It is exactly six bytes long and contains "sNaPpY" in ASCII. This means that 72 | a valid Snappy framed stream always starts with the bytes 73 | 74 | 0xff 0x06 0x00 0x00 0x73 0x4e 0x61 0x50 0x70 0x59 75 | 76 | The stream identifier chunk can come multiple times in the stream besides 77 | the first; if such a chunk shows up, it should simply be ignored, assuming 78 | it has the right length and contents. This allows for easy concatenation of 79 | compressed files without the need for re-framing. 80 | 81 | 82 | 4.2. Compressed data (chunk type 0x00) 83 | 84 | Compressed data chunks contain a normal Snappy compressed bitstream; 85 | see the compressed format specification. The compressed data is preceded by 86 | the CRC-32C (see section 3) of the _uncompressed_ data. 87 | 88 | Note that the data portion of the chunk, i.e., the compressed contents, 89 | can be at most 16777211 bytes (2^24 - 1, minus the checksum). 90 | However, we place an additional restriction that the uncompressed data 91 | in a chunk must be no longer than 65536 bytes. This allows consumers to 92 | easily use small fixed-size buffers. 93 | 94 | 95 | 4.3. Uncompressed data (chunk type 0x01) 96 | 97 | Uncompressed data chunks allow a compressor to send uncompressed, 98 | raw data; this is useful if, for instance, uncompressible or 99 | near-incompressible data is detected, and faster decompression is desired. 100 | 101 | As in the compressed chunks, the data is preceded by its own masked 102 | CRC-32C (see section 3). 103 | 104 | An uncompressed data chunk, like compressed data chunks, should contain 105 | no more than 65536 data bytes, so the maximum legal chunk length with the 106 | checksum is 65540. 107 | 108 | 109 | 4.4. Padding (chunk type 0xfe) 110 | 111 | Padding chunks allow a compressor to increase the size of the data stream 112 | so that it complies with external demands, e.g. that the total number of 113 | bytes is a multiple of some value. 114 | 115 | All bytes of the padding chunk, except the chunk byte itself and the length, 116 | should be zero, but decompressors must not try to interpret or verify the 117 | padding data in any way. 118 | 119 | 120 | 4.5. Reserved unskippable chunks (chunk types 0x02-0x7f) 121 | 122 | These are reserved for future expansion. A decoder that sees such a chunk 123 | should immediately return an error, as it must assume it cannot decode the 124 | stream correctly. 125 | 126 | Future versions of this specification may define meanings for these chunks. 127 | 128 | 129 | 4.6. Reserved skippable chunks (chunk types 0x80-0xfd) 130 | 131 | These are also reserved for future expansion, but unlike the chunks 132 | described in 4.5, a decoder seeing these must skip them and continue 133 | decoding. 134 | 135 | Future versions of this specification may define meanings for these chunks. 136 | -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.7/snappy-c.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Martin Gieseking . 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are 6 | * met: 7 | * 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above 11 | * copyright notice, this list of conditions and the following disclaimer 12 | * in the documentation and/or other materials provided with the 13 | * distribution. 14 | * * Neither the name of Google Inc. nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | * Plain C interface (a wrapper around the C++ implementation). 31 | */ 32 | 33 | #ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_C_H_ 34 | #define THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_C_H_ 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | #include 41 | 42 | /* 43 | * Return values; see the documentation for each function to know 44 | * what each can return. 45 | */ 46 | typedef enum { 47 | SNAPPY_OK = 0, 48 | SNAPPY_INVALID_INPUT = 1, 49 | SNAPPY_BUFFER_TOO_SMALL = 2 50 | } snappy_status; 51 | 52 | /* 53 | * Takes the data stored in "input[0..input_length-1]" and stores 54 | * it in the array pointed to by "compressed". 55 | * 56 | * signals the space available in "compressed". 57 | * If it is not at least equal to "snappy_max_compressed_length(input_length)", 58 | * SNAPPY_BUFFER_TOO_SMALL is returned. After successful compression, 59 | * contains the true length of the compressed output, 60 | * and SNAPPY_OK is returned. 61 | * 62 | * Example: 63 | * size_t output_length = snappy_max_compressed_length(input_length); 64 | * char* output = (char*)malloc(output_length); 65 | * if (snappy_compress(input, input_length, output, &output_length) 66 | * == SNAPPY_OK) { 67 | * ... Process(output, output_length) ... 68 | * } 69 | * free(output); 70 | */ 71 | snappy_status snappy_compress(const char* input, 72 | size_t input_length, 73 | char* compressed, 74 | size_t* compressed_length); 75 | 76 | /* 77 | * Given data in "compressed[0..compressed_length-1]" generated by 78 | * calling the snappy_compress routine, this routine stores 79 | * the uncompressed data to 80 | * uncompressed[0..uncompressed_length-1]. 81 | * Returns failure (a value not equal to SNAPPY_OK) if the message 82 | * is corrupted and could not be decrypted. 83 | * 84 | * signals the space available in "uncompressed". 85 | * If it is not at least equal to the value returned by 86 | * snappy_uncompressed_length for this stream, SNAPPY_BUFFER_TOO_SMALL 87 | * is returned. After successful decompression, 88 | * contains the true length of the decompressed output. 89 | * 90 | * Example: 91 | * size_t output_length; 92 | * if (snappy_uncompressed_length(input, input_length, &output_length) 93 | * != SNAPPY_OK) { 94 | * ... fail ... 95 | * } 96 | * char* output = (char*)malloc(output_length); 97 | * if (snappy_uncompress(input, input_length, output, &output_length) 98 | * == SNAPPY_OK) { 99 | * ... Process(output, output_length) ... 100 | * } 101 | * free(output); 102 | */ 103 | snappy_status snappy_uncompress(const char* compressed, 104 | size_t compressed_length, 105 | char* uncompressed, 106 | size_t* uncompressed_length); 107 | 108 | /* 109 | * Returns the maximal size of the compressed representation of 110 | * input data that is "source_length" bytes in length. 111 | */ 112 | size_t snappy_max_compressed_length(size_t source_length); 113 | 114 | /* 115 | * REQUIRES: "compressed[]" was produced by snappy_compress() 116 | * Returns SNAPPY_OK and stores the length of the uncompressed data in 117 | * *result normally. Returns SNAPPY_INVALID_INPUT on parsing error. 118 | * This operation takes O(1) time. 119 | */ 120 | snappy_status snappy_uncompressed_length(const char* compressed, 121 | size_t compressed_length, 122 | size_t* result); 123 | 124 | /* 125 | * Check if the contents of "compressed[]" can be uncompressed successfully. 126 | * Does not return the uncompressed data; if so, returns SNAPPY_OK, 127 | * or if not, returns SNAPPY_INVALID_INPUT. 128 | * Takes time proportional to compressed_length, but is usually at least a 129 | * factor of four faster than actual decompression. 130 | */ 131 | snappy_status snappy_validate_compressed_buffer(const char* compressed, 132 | size_t compressed_length); 133 | 134 | #ifdef __cplusplus 135 | } // extern "C" 136 | #endif 137 | 138 | #endif /* THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_C_H_ */ 139 | -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.7/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.1) 2 | project(Snappy VERSION 1.1.7 LANGUAGES C CXX) 3 | 4 | # BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to make 5 | # it prominent in the GUI. 6 | option(BUILD_SHARED_LIBS "Build shared libraries(DLLs)." OFF) 7 | 8 | option(SNAPPY_BUILD_TESTS "Build Snappy's own tests." ON) 9 | 10 | include(TestBigEndian) 11 | test_big_endian(SNAPPY_IS_BIG_ENDIAN) 12 | 13 | include(CheckIncludeFile) 14 | check_include_file("byteswap.h" HAVE_BYTESWAP_H) 15 | check_include_file("stddef.h" HAVE_STDDEF_H) 16 | check_include_file("stdint.h" HAVE_STDINT_H) 17 | check_include_file("sys/endian.h" HAVE_SYS_ENDIAN_H) 18 | check_include_file("sys/mman.h" HAVE_SYS_MMAN_H) 19 | check_include_file("sys/resource.h" HAVE_SYS_RESOURCE_H) 20 | check_include_file("sys/time.h" HAVE_SYS_TIME_H) 21 | check_include_file("sys/uio.h" HAVE_SYS_UIO_H) 22 | check_include_file("unistd.h" HAVE_UNISTD_H) 23 | check_include_file("windows.h" HAVE_WINDOWS_H) 24 | 25 | include(CheckLibraryExists) 26 | check_library_exists(z zlibVersion "" HAVE_LIBZ) 27 | check_library_exists(lzo2 lzo1x_1_15_compress "" HAVE_LIBLZO2) 28 | 29 | include(CheckCXXSourceCompiles) 30 | check_cxx_source_compiles( 31 | "int main(void) { return __builtin_expect(0, 1); }" HAVE_BUILTIN_EXPECT) 32 | 33 | check_cxx_source_compiles( 34 | "int main(void) { return __builtin_ctzll(0); }" HAVE_BUILTIN_CTZ) 35 | 36 | include(CheckSymbolExists) 37 | check_symbol_exists("mmap" "sys/mman.h" HAVE_FUNC_MMAP) 38 | check_symbol_exists("sysconf" "unistd.h" HAVE_FUNC_SYSCONF) 39 | 40 | find_package(GTest QUIET) 41 | if(GTEST_FOUND) 42 | set(HAVE_GTEST 1) 43 | endif(GTEST_FOUND) 44 | 45 | find_package(Gflags QUIET) 46 | if(GFLAGS_FOUND) 47 | set(HAVE_GFLAGS 1) 48 | endif(GFLAGS_FOUND) 49 | 50 | configure_file( 51 | "${PROJECT_SOURCE_DIR}/cmake/config.h.in" 52 | "${PROJECT_BINARY_DIR}/config.h" 53 | ) 54 | 55 | # We don't want to define HAVE_ macros in public headers. Instead, we use 56 | # CMake's variable substitution with 0/1 variables, which will be seen by the 57 | # preprocessor as constants. 58 | set(HAVE_STDINT_H_01 ${HAVE_STDINT_H}) 59 | set(HAVE_STDDEF_H_01 ${HAVE_STDDEF_H}) 60 | set(HAVE_SYS_UIO_H_01 ${HAVE_SYS_UIO_H}) 61 | if(NOT HAVE_STDINT_H_01) 62 | set(HAVE_STDINT_H_01 0) 63 | endif(NOT HAVE_STDINT_H_01) 64 | if(NOT HAVE_STDDEF_H_01) 65 | set(HAVE_STDDEF_H_01 0) 66 | endif(NOT HAVE_STDDEF_H_01) 67 | if(NOT HAVE_SYS_UIO_H_01) 68 | set(HAVE_SYS_UIO_H_01 0) 69 | endif(NOT HAVE_SYS_UIO_H_01) 70 | 71 | configure_file( 72 | "${PROJECT_SOURCE_DIR}/snappy-stubs-public.h.in" 73 | "${PROJECT_BINARY_DIR}/snappy-stubs-public.h") 74 | 75 | add_library(snappy "") 76 | target_sources(snappy 77 | PRIVATE 78 | "${PROJECT_SOURCE_DIR}/snappy-internal.h" 79 | "${PROJECT_SOURCE_DIR}/snappy-stubs-internal.h" 80 | "${PROJECT_SOURCE_DIR}/snappy-c.cc" 81 | "${PROJECT_SOURCE_DIR}/snappy-sinksource.cc" 82 | "${PROJECT_SOURCE_DIR}/snappy-stubs-internal.cc" 83 | "${PROJECT_SOURCE_DIR}/snappy.cc" 84 | "${PROJECT_BINARY_DIR}/config.h" 85 | 86 | # Only CMake 3.3+ supports PUBLIC sources in targets exported by "install". 87 | $<$:PUBLIC> 88 | $ 89 | $ 90 | $ 91 | $ 92 | $ 93 | $ 94 | $ 95 | $ 96 | ) 97 | target_include_directories(snappy 98 | PUBLIC 99 | $ 100 | $ 101 | $ 102 | ) 103 | set_target_properties(snappy 104 | PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR}) 105 | 106 | target_compile_definitions(snappy PRIVATE -DHAVE_CONFIG_H) 107 | if(BUILD_SHARED_LIBS) 108 | set_target_properties(snappy PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON) 109 | endif(BUILD_SHARED_LIBS) 110 | 111 | if(SNAPPY_BUILD_TESTS) 112 | enable_testing() 113 | 114 | add_executable(snappy_unittest "") 115 | target_sources(snappy_unittest 116 | PRIVATE 117 | "${PROJECT_SOURCE_DIR}/snappy_unittest.cc" 118 | "${PROJECT_SOURCE_DIR}/snappy-test.cc" 119 | ) 120 | target_compile_definitions(snappy_unittest PRIVATE -DHAVE_CONFIG_H) 121 | target_link_libraries(snappy_unittest snappy ${GFLAGS_LIBRARIES}) 122 | 123 | if(HAVE_LIBZ) 124 | target_link_libraries(snappy_unittest z) 125 | endif(HAVE_LIBZ) 126 | if(HAVE_LIBLZO2) 127 | target_link_libraries(snappy_unittest lzo2) 128 | endif(HAVE_LIBLZO2) 129 | 130 | target_include_directories(snappy_unittest 131 | BEFORE PRIVATE 132 | "${PROJECT_SOURCE_DIR}" 133 | "${GTEST_INCLUDE_DIRS}" 134 | "${GFLAGS_INCLUDE_DIRS}" 135 | ) 136 | 137 | add_test( 138 | NAME snappy_unittest 139 | WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" 140 | COMMAND "${PROJECT_BINARY_DIR}/snappy_unittest") 141 | endif(SNAPPY_BUILD_TESTS) 142 | 143 | include(GNUInstallDirs) 144 | install(TARGETS snappy 145 | EXPORT SnappyTargets 146 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} 147 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} 148 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} 149 | ) 150 | install( 151 | FILES 152 | "${PROJECT_SOURCE_DIR}/snappy-c.h" 153 | "${PROJECT_SOURCE_DIR}/snappy-sinksource.h" 154 | "${PROJECT_SOURCE_DIR}/snappy.h" 155 | "${PROJECT_BINARY_DIR}/snappy-stubs-public.h" 156 | DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} 157 | ) 158 | 159 | include(CMakePackageConfigHelpers) 160 | write_basic_package_version_file( 161 | "${PROJECT_BINARY_DIR}/SnappyConfigVersion.cmake" 162 | COMPATIBILITY SameMajorVersion 163 | ) 164 | install( 165 | EXPORT SnappyTargets 166 | NAMESPACE Snappy:: 167 | DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Snappy" 168 | ) 169 | install( 170 | FILES 171 | "${PROJECT_SOURCE_DIR}/cmake/SnappyConfig.cmake" 172 | "${PROJECT_BINARY_DIR}/SnappyConfigVersion.cmake" 173 | DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Snappy" 174 | ) 175 | -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.7/NEWS: -------------------------------------------------------------------------------- 1 | Snappy v1.1.7, August 24th 2017: 2 | 3 | * Improved CMake build support for 64-bit Linux distributions. 4 | 5 | * MSVC builds now use MSVC-specific intrinsics that map to clzll. 6 | 7 | * ARM64 (AArch64) builds use the code paths optimized for 64-bit processors. 8 | 9 | Snappy v1.1.6, July 12th 2017: 10 | 11 | This is a re-release of v1.1.5 with proper SONAME / SOVERSION values. 12 | 13 | Snappy v1.1.5, June 28th 2017: 14 | 15 | This release has broken SONAME / SOVERSION values. Users of snappy as a shared 16 | library should avoid 1.1.5 and use 1.1.6 instead. SONAME / SOVERSION errors will 17 | manifest as the dynamic library loader complaining that it cannot find snappy's 18 | shared library file (libsnappy.so / libsnappy.dylib), or that the library it 19 | found does not have the required version. 1.1.6 has the same code as 1.1.5, but 20 | carries build configuration fixes for the issues above. 21 | 22 | * Add CMake build support. The autoconf build support is now deprecated, and 23 | will be removed in the next release. 24 | 25 | * Add AppVeyor configuration, for Windows CI coverage. 26 | 27 | * Small performance improvement on little-endian PowerPC. 28 | 29 | * Small performance improvement on LLVM with position-independent executables. 30 | 31 | * Fix a few issues with various build environments. 32 | 33 | Snappy v1.1.4, January 25th 2017: 34 | 35 | * Fix a 1% performance regression when snappy is used in PIE executables. 36 | 37 | * Improve compression performance by 5%. 38 | 39 | * Improve decompression performance by 20%. 40 | 41 | Snappy v1.1.3, July 6th 2015: 42 | 43 | This is the first release to be done from GitHub, which means that 44 | some minor things like the ChangeLog format has changed (git log 45 | format instead of svn log). 46 | 47 | * Add support for Uncompress() from a Source to a Sink. 48 | 49 | * Various minor changes to improve MSVC support; in particular, 50 | the unit tests now compile and run under MSVC. 51 | 52 | 53 | Snappy v1.1.2, February 28th 2014: 54 | 55 | This is a maintenance release with no changes to the actual library 56 | source code. 57 | 58 | * Stop distributing benchmark data files that have unclear 59 | or unsuitable licensing. 60 | 61 | * Add support for padding chunks in the framing format. 62 | 63 | 64 | Snappy v1.1.1, October 15th 2013: 65 | 66 | * Add support for uncompressing to iovecs (scatter I/O). 67 | The bulk of this patch was contributed by Mohit Aron. 68 | 69 | * Speed up decompression by ~2%; much more so (~13-20%) on 70 | a few benchmarks on given compilers and CPUs. 71 | 72 | * Fix a few issues with MSVC compilation. 73 | 74 | * Support truncated test data in the benchmark. 75 | 76 | 77 | Snappy v1.1.0, January 18th 2013: 78 | 79 | * Snappy now uses 64 kB block size instead of 32 kB. On average, 80 | this means it compresses about 3% denser (more so for some 81 | inputs), at the same or better speeds. 82 | 83 | * libsnappy no longer depends on iostream. 84 | 85 | * Some small performance improvements in compression on x86 86 | (0.5–1%). 87 | 88 | * Various portability fixes for ARM-based platforms, for MSVC, 89 | and for GNU/Hurd. 90 | 91 | 92 | Snappy v1.0.5, February 24th 2012: 93 | 94 | * More speed improvements. Exactly how big will depend on 95 | the architecture: 96 | 97 | - 3–10% faster decompression for the base case (x86-64). 98 | 99 | - ARMv7 and higher can now use unaligned accesses, 100 | and will see about 30% faster decompression and 101 | 20–40% faster compression. 102 | 103 | - 32-bit platforms (ARM and 32-bit x86) will see 2–5% 104 | faster compression. 105 | 106 | These are all cumulative (e.g., ARM gets all three speedups). 107 | 108 | * Fixed an issue where the unit test would crash on system 109 | with less than 256 MB address space available, 110 | e.g. some embedded platforms. 111 | 112 | * Added a framing format description, for use over e.g. HTTP, 113 | or for a command-line compressor. We do not have any 114 | implementations of this at the current point, but there seems 115 | to be enough of a general interest in the topic. 116 | Also make the format description slightly clearer. 117 | 118 | * Remove some compile-time warnings in -Wall 119 | (mostly signed/unsigned comparisons), for easier embedding 120 | into projects that use -Wall -Werror. 121 | 122 | 123 | Snappy v1.0.4, September 15th 2011: 124 | 125 | * Speeded up the decompressor somewhat; typically about 2–8% 126 | for Core i7, in 64-bit mode (comparable for Opteron). 127 | Somewhat more for some tests, almost no gain for others. 128 | 129 | * Make Snappy compile on certain platforms it didn't before 130 | (Solaris with SunPro C++, HP-UX, AIX). 131 | 132 | * Correct some minor errors in the format description. 133 | 134 | 135 | Snappy v1.0.3, June 2nd 2011: 136 | 137 | * Speeded up the decompressor somewhat; about 3-6% for Core 2, 138 | 6-13% for Core i7, and 5-12% for Opteron (all in 64-bit mode). 139 | 140 | * Added compressed format documentation. This text is new, 141 | but an earlier version from Zeev Tarantov was used as reference. 142 | 143 | * Only link snappy_unittest against -lz and other autodetected 144 | libraries, not libsnappy.so (which doesn't need any such dependency). 145 | 146 | * Fixed some display issues in the microbenchmarks, one of which would 147 | frequently make the test crash on GNU/Hurd. 148 | 149 | 150 | Snappy v1.0.2, April 29th 2011: 151 | 152 | * Relicense to a BSD-type license. 153 | 154 | * Added C bindings, contributed by Martin Gieseking. 155 | 156 | * More Win32 fixes, in particular for MSVC. 157 | 158 | * Replace geo.protodata with a newer version. 159 | 160 | * Fix timing inaccuracies in the unit test when comparing Snappy 161 | to other algorithms. 162 | 163 | 164 | Snappy v1.0.1, March 25th 2011: 165 | 166 | This is a maintenance release, mostly containing minor fixes. 167 | There is no new functionality. The most important fixes include: 168 | 169 | * The COPYING file and all licensing headers now correctly state that 170 | Snappy is licensed under the Apache 2.0 license. 171 | 172 | * snappy_unittest should now compile natively under Windows, 173 | as well as on embedded systems with no mmap(). 174 | 175 | * Various autotools nits have been fixed. 176 | 177 | 178 | Snappy v1.0, March 17th 2011: 179 | 180 | * Initial version. 181 | -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.7/README.md: -------------------------------------------------------------------------------- 1 | Snappy, a fast compressor/decompressor. 2 | 3 | 4 | Introduction 5 | ============ 6 | 7 | Snappy is a compression/decompression library. It does not aim for maximum 8 | compression, or compatibility with any other compression library; instead, 9 | it aims for very high speeds and reasonable compression. For instance, 10 | compared to the fastest mode of zlib, Snappy is an order of magnitude faster 11 | for most inputs, but the resulting compressed files are anywhere from 20% to 12 | 100% bigger. (For more information, see "Performance", below.) 13 | 14 | Snappy has the following properties: 15 | 16 | * Fast: Compression speeds at 250 MB/sec and beyond, with no assembler code. 17 | See "Performance" below. 18 | * Stable: Over the last few years, Snappy has compressed and decompressed 19 | petabytes of data in Google's production environment. The Snappy bitstream 20 | format is stable and will not change between versions. 21 | * Robust: The Snappy decompressor is designed not to crash in the face of 22 | corrupted or malicious input. 23 | * Free and open source software: Snappy is licensed under a BSD-type license. 24 | For more information, see the included COPYING file. 25 | 26 | Snappy has previously been called "Zippy" in some Google presentations 27 | and the like. 28 | 29 | 30 | Performance 31 | =========== 32 | 33 | Snappy is intended to be fast. On a single core of a Core i7 processor 34 | in 64-bit mode, it compresses at about 250 MB/sec or more and decompresses at 35 | about 500 MB/sec or more. (These numbers are for the slowest inputs in our 36 | benchmark suite; others are much faster.) In our tests, Snappy usually 37 | is faster than algorithms in the same class (e.g. LZO, LZF, QuickLZ, 38 | etc.) while achieving comparable compression ratios. 39 | 40 | Typical compression ratios (based on the benchmark suite) are about 1.5-1.7x 41 | for plain text, about 2-4x for HTML, and of course 1.0x for JPEGs, PNGs and 42 | other already-compressed data. Similar numbers for zlib in its fastest mode 43 | are 2.6-2.8x, 3-7x and 1.0x, respectively. More sophisticated algorithms are 44 | capable of achieving yet higher compression rates, although usually at the 45 | expense of speed. Of course, compression ratio will vary significantly with 46 | the input. 47 | 48 | Although Snappy should be fairly portable, it is primarily optimized 49 | for 64-bit x86-compatible processors, and may run slower in other environments. 50 | In particular: 51 | 52 | - Snappy uses 64-bit operations in several places to process more data at 53 | once than would otherwise be possible. 54 | - Snappy assumes unaligned 32- and 64-bit loads and stores are cheap. 55 | On some platforms, these must be emulated with single-byte loads 56 | and stores, which is much slower. 57 | - Snappy assumes little-endian throughout, and needs to byte-swap data in 58 | several places if running on a big-endian platform. 59 | 60 | Experience has shown that even heavily tuned code can be improved. 61 | Performance optimizations, whether for 64-bit x86 or other platforms, 62 | are of course most welcome; see "Contact", below. 63 | 64 | 65 | Building 66 | ======== 67 | 68 | CMake is supported and autotools will soon be deprecated. 69 | You need CMake 3.4 or above to build: 70 | 71 | mkdir build 72 | cd build && cmake ../ && make 73 | 74 | 75 | Usage 76 | ===== 77 | 78 | Note that Snappy, both the implementation and the main interface, 79 | is written in C++. However, several third-party bindings to other languages 80 | are available; see the home page at http://google.github.io/snappy/ 81 | for more information. Also, if you want to use Snappy from C code, you can 82 | use the included C bindings in snappy-c.h. 83 | 84 | To use Snappy from your own C++ program, include the file "snappy.h" from 85 | your calling file, and link against the compiled library. 86 | 87 | There are many ways to call Snappy, but the simplest possible is 88 | 89 | snappy::Compress(input.data(), input.size(), &output); 90 | 91 | and similarly 92 | 93 | snappy::Uncompress(input.data(), input.size(), &output); 94 | 95 | where "input" and "output" are both instances of std::string. 96 | 97 | There are other interfaces that are more flexible in various ways, including 98 | support for custom (non-array) input sources. See the header file for more 99 | information. 100 | 101 | 102 | Tests and benchmarks 103 | ==================== 104 | 105 | When you compile Snappy, snappy_unittest is compiled in addition to the 106 | library itself. You do not need it to use the compressor from your own library, 107 | but it contains several useful components for Snappy development. 108 | 109 | First of all, it contains unit tests, verifying correctness on your machine in 110 | various scenarios. If you want to change or optimize Snappy, please run the 111 | tests to verify you have not broken anything. Note that if you have the 112 | Google Test library installed, unit test behavior (especially failures) will be 113 | significantly more user-friendly. You can find Google Test at 114 | 115 | http://github.com/google/googletest 116 | 117 | You probably also want the gflags library for handling of command-line flags; 118 | you can find it at 119 | 120 | http://gflags.github.io/gflags/ 121 | 122 | In addition to the unit tests, snappy contains microbenchmarks used to 123 | tune compression and decompression performance. These are automatically run 124 | before the unit tests, but you can disable them using the flag 125 | --run_microbenchmarks=false if you have gflags installed (otherwise you will 126 | need to edit the source). 127 | 128 | Finally, snappy can benchmark Snappy against a few other compression libraries 129 | (zlib, LZO, LZF, and QuickLZ), if they were detected at configure time. 130 | To benchmark using a given file, give the compression algorithm you want to test 131 | Snappy against (e.g. --zlib) and then a list of one or more file names on the 132 | command line. The testdata/ directory contains the files used by the 133 | microbenchmark, which should provide a reasonably balanced starting point for 134 | benchmarking. (Note that baddata[1-3].snappy are not intended as benchmarks; they 135 | are used to verify correctness in the presence of corrupted data in the unit 136 | test.) 137 | 138 | 139 | Contact 140 | ======= 141 | 142 | Snappy is distributed through GitHub. For the latest version, a bug tracker, 143 | and other information, see 144 | 145 | http://google.github.io/snappy/ 146 | 147 | or the repository at 148 | 149 | https://github.com/google/snappy 150 | -------------------------------------------------------------------------------- /src/binding.cc: -------------------------------------------------------------------------------- 1 | #include "./binding.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include // memcpy 8 | 9 | #include 10 | 11 | namespace nodesnappy { 12 | 13 | class CompressWorker : public Nan::AsyncWorker { 14 | public: 15 | CompressWorker(std::string* input, Nan::Callback *callback) 16 | : Nan::AsyncWorker(callback), input(input) {} 17 | 18 | ~CompressWorker() { 19 | delete input; 20 | } 21 | 22 | void Execute() { 23 | snappy::Compress(input->data(), input->length(), &dst); 24 | } 25 | 26 | void HandleOKCallback() { 27 | Nan::HandleScope scope; 28 | 29 | v8::Local res = Nan::NewBuffer(dst.length()).ToLocalChecked(); 30 | memcpy(node::Buffer::Data(res), dst.c_str(), dst.length()); 31 | 32 | v8::Local argv[] = { 33 | Nan::Null() 34 | , res 35 | }; 36 | 37 | callback->Call(2, argv, async_resource); 38 | } 39 | 40 | private: 41 | std::string* input; 42 | std::string dst; 43 | }; 44 | 45 | class IsValidCompressedWorker : public Nan::AsyncWorker { 46 | public: IsValidCompressedWorker(std::string* input, Nan::Callback * callback) 47 | : Nan::AsyncWorker(callback), input(input) {} 48 | 49 | ~IsValidCompressedWorker() { 50 | delete input; 51 | } 52 | 53 | void Execute() { 54 | res = snappy::IsValidCompressedBuffer(input->data(), input->length()); 55 | } 56 | 57 | void HandleOKCallback() { 58 | Nan::HandleScope scope; 59 | 60 | v8::Local argv[] = { 61 | Nan::Null() 62 | , res ? Nan::True() : Nan::False() 63 | }; 64 | 65 | callback->Call(2, argv, async_resource); 66 | } 67 | 68 | private: 69 | std::string* input; 70 | bool res; 71 | }; 72 | 73 | class UncompressWorker : public Nan::AsyncWorker { 74 | public: 75 | UncompressWorker(std::string* input, bool asBuffer, Nan::Callback *callback) 76 | : Nan::AsyncWorker(callback), input(input), asBuffer(asBuffer) {} 77 | 78 | ~UncompressWorker() { 79 | delete input; 80 | } 81 | 82 | void Execute() { 83 | if (!snappy::Uncompress(input->data(), input->length(), &dst)) 84 | SetErrorMessage("Invalid input"); 85 | } 86 | 87 | void HandleOKCallback() { 88 | Nan::HandleScope scope; 89 | 90 | v8::Local res; 91 | if (asBuffer) { 92 | res = Nan::NewBuffer(dst.length()).ToLocalChecked(); 93 | memcpy(node::Buffer::Data(res.As()), dst.c_str(), dst.length()); 94 | } else { 95 | res = Nan::New(dst.c_str(), dst.length()).ToLocalChecked(); 96 | } 97 | 98 | v8::Local argv[] = { 99 | Nan::Null() 100 | , res 101 | }; 102 | 103 | callback->Call(2, argv, async_resource); 104 | } 105 | 106 | private: 107 | std::string* input; 108 | std::string dst; 109 | bool asBuffer; 110 | }; 111 | 112 | NAN_METHOD(Compress) { 113 | std::string *input; 114 | 115 | if (node::Buffer::HasInstance(info[0].As())) { 116 | v8::Local object = info[0].As(); 117 | size_t length = node::Buffer::Length(object); 118 | const char *data = node::Buffer::Data(object); 119 | input = new std::string(data, length); 120 | } else { 121 | Nan::Utf8String param1(info[0].As()); 122 | input = new std::string(*param1); 123 | } 124 | 125 | Nan::Callback* callback = new Nan::Callback( 126 | v8::Local::Cast(info[1]) 127 | ); 128 | 129 | CompressWorker* worker = new CompressWorker( 130 | input, callback 131 | ); 132 | 133 | Nan::AsyncQueueWorker(worker); 134 | 135 | return; 136 | } 137 | 138 | NAN_METHOD(CompressSync) { 139 | std::string input; 140 | std::string dst; 141 | 142 | if (node::Buffer::HasInstance(info[0].As())) { 143 | v8::Local object = info[0].As(); 144 | size_t length = node::Buffer::Length(object); 145 | const char *data = node::Buffer::Data(object); 146 | input.assign(data, length); 147 | } else { 148 | Nan::Utf8String param1(info[0].As()); 149 | input.assign(*param1); 150 | } 151 | 152 | snappy::Compress(input.data(), input.length(), &dst); 153 | 154 | v8::Local res = Nan::NewBuffer(dst.length()).ToLocalChecked(); 155 | memcpy(node::Buffer::Data(res), dst.c_str(), dst.length()); 156 | 157 | info.GetReturnValue().Set(res); 158 | } 159 | 160 | NAN_METHOD(IsValidCompressed) { 161 | v8::Local object = info[0].As(); 162 | size_t length = node::Buffer::Length(object); 163 | const char *data = node::Buffer::Data(object); 164 | std::string *input = new std::string(data, length); 165 | 166 | Nan::Callback* callback = new Nan::Callback( 167 | v8::Local::Cast(info[1]) 168 | ); 169 | 170 | IsValidCompressedWorker* worker = new IsValidCompressedWorker( 171 | input, callback 172 | ); 173 | 174 | Nan::AsyncQueueWorker(worker); 175 | 176 | return; 177 | } 178 | 179 | NAN_METHOD(IsValidCompressedSync) { 180 | 181 | v8::Local object = info[0].As(); 182 | size_t length = node::Buffer::Length(object); 183 | const char *data = node::Buffer::Data(object); 184 | 185 | bool res = snappy::IsValidCompressedBuffer(data, length); 186 | 187 | 188 | info.GetReturnValue().Set((res ? Nan::True() : Nan::False())); 189 | } 190 | 191 | NAN_METHOD(Uncompress) { 192 | 193 | v8::Local object = info[0].As(); 194 | v8::Local optionsObj = info[1].As(); 195 | size_t length = node::Buffer::Length(object); 196 | const char *data = node::Buffer::Data(object); 197 | std::string *input = new std::string(data, length); 198 | bool asBuffer = Nan::To( 199 | Nan::Get(optionsObj, Nan::New("asBuffer").ToLocalChecked()) 200 | .ToLocalChecked()).FromJust(); 201 | 202 | Nan::Callback* callback = new Nan::Callback( 203 | v8::Local::Cast(info[2]) 204 | ); 205 | 206 | UncompressWorker* worker = new UncompressWorker( 207 | input, asBuffer, callback 208 | ); 209 | 210 | Nan::AsyncQueueWorker(worker); 211 | 212 | return; 213 | } 214 | 215 | NAN_METHOD(UncompressSync) { 216 | std::string dst; 217 | 218 | v8::Local object = info[0].As(); 219 | size_t length = node::Buffer::Length(object); 220 | const char *data = node::Buffer::Data(object); 221 | 222 | v8::Local optionsObj = info[1].As(); 223 | bool asBuffer = Nan::To( 224 | Nan::Get(optionsObj, Nan::New("asBuffer").ToLocalChecked()) 225 | .ToLocalChecked()).FromJust(); 226 | 227 | if (!snappy::Uncompress(data, length, &dst)) { 228 | return Nan::ThrowError("Invalid input"); 229 | } 230 | 231 | v8::Local res; 232 | if (asBuffer) { 233 | res = Nan::NewBuffer(dst.length()).ToLocalChecked(); 234 | memcpy(node::Buffer::Data(res.As()), dst.c_str(), dst.length()); 235 | } else { 236 | res = Nan::New(dst.c_str(), dst.length()).ToLocalChecked(); 237 | } 238 | 239 | info.GetReturnValue().Set(res); 240 | } 241 | 242 | extern "C" 243 | NAN_MODULE_INIT(init) { 244 | Nan::SetMethod(target, "compress", Compress); 245 | Nan::SetMethod(target, "compressSync", CompressSync); 246 | Nan::SetMethod(target, "isValidCompressed", IsValidCompressed); 247 | Nan::SetMethod(target, "isValidCompressedSync", IsValidCompressedSync); 248 | Nan::SetMethod(target, "uncompress", Uncompress); 249 | Nan::SetMethod(target, "uncompressSync", UncompressSync); 250 | } 251 | 252 | NAN_MODULE_WORKER_ENABLED(binding, init) 253 | } // namespace nodesnappy 254 | -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.7/snappy-sinksource.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. All Rights Reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of Google Inc. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #ifndef THIRD_PARTY_SNAPPY_SNAPPY_SINKSOURCE_H_ 30 | #define THIRD_PARTY_SNAPPY_SNAPPY_SINKSOURCE_H_ 31 | 32 | #include 33 | 34 | namespace snappy { 35 | 36 | // A Sink is an interface that consumes a sequence of bytes. 37 | class Sink { 38 | public: 39 | Sink() { } 40 | virtual ~Sink(); 41 | 42 | // Append "bytes[0,n-1]" to this. 43 | virtual void Append(const char* bytes, size_t n) = 0; 44 | 45 | // Returns a writable buffer of the specified length for appending. 46 | // May return a pointer to the caller-owned scratch buffer which 47 | // must have at least the indicated length. The returned buffer is 48 | // only valid until the next operation on this Sink. 49 | // 50 | // After writing at most "length" bytes, call Append() with the 51 | // pointer returned from this function and the number of bytes 52 | // written. Many Append() implementations will avoid copying 53 | // bytes if this function returned an internal buffer. 54 | // 55 | // If a non-scratch buffer is returned, the caller may only pass a 56 | // prefix of it to Append(). That is, it is not correct to pass an 57 | // interior pointer of the returned array to Append(). 58 | // 59 | // The default implementation always returns the scratch buffer. 60 | virtual char* GetAppendBuffer(size_t length, char* scratch); 61 | 62 | // For higher performance, Sink implementations can provide custom 63 | // AppendAndTakeOwnership() and GetAppendBufferVariable() methods. 64 | // These methods can reduce the number of copies done during 65 | // compression/decompression. 66 | 67 | // Append "bytes[0,n-1] to the sink. Takes ownership of "bytes" 68 | // and calls the deleter function as (*deleter)(deleter_arg, bytes, n) 69 | // to free the buffer. deleter function must be non NULL. 70 | // 71 | // The default implementation just calls Append and frees "bytes". 72 | // Other implementations may avoid a copy while appending the buffer. 73 | virtual void AppendAndTakeOwnership( 74 | char* bytes, size_t n, void (*deleter)(void*, const char*, size_t), 75 | void *deleter_arg); 76 | 77 | // Returns a writable buffer for appending and writes the buffer's capacity to 78 | // *allocated_size. Guarantees *allocated_size >= min_size. 79 | // May return a pointer to the caller-owned scratch buffer which must have 80 | // scratch_size >= min_size. 81 | // 82 | // The returned buffer is only valid until the next operation 83 | // on this ByteSink. 84 | // 85 | // After writing at most *allocated_size bytes, call Append() with the 86 | // pointer returned from this function and the number of bytes written. 87 | // Many Append() implementations will avoid copying bytes if this function 88 | // returned an internal buffer. 89 | // 90 | // If the sink implementation allocates or reallocates an internal buffer, 91 | // it should use the desired_size_hint if appropriate. If a caller cannot 92 | // provide a reasonable guess at the desired capacity, it should set 93 | // desired_size_hint = 0. 94 | // 95 | // If a non-scratch buffer is returned, the caller may only pass 96 | // a prefix to it to Append(). That is, it is not correct to pass an 97 | // interior pointer to Append(). 98 | // 99 | // The default implementation always returns the scratch buffer. 100 | virtual char* GetAppendBufferVariable( 101 | size_t min_size, size_t desired_size_hint, char* scratch, 102 | size_t scratch_size, size_t* allocated_size); 103 | 104 | private: 105 | // No copying 106 | Sink(const Sink&); 107 | void operator=(const Sink&); 108 | }; 109 | 110 | // A Source is an interface that yields a sequence of bytes 111 | class Source { 112 | public: 113 | Source() { } 114 | virtual ~Source(); 115 | 116 | // Return the number of bytes left to read from the source 117 | virtual size_t Available() const = 0; 118 | 119 | // Peek at the next flat region of the source. Does not reposition 120 | // the source. The returned region is empty iff Available()==0. 121 | // 122 | // Returns a pointer to the beginning of the region and store its 123 | // length in *len. 124 | // 125 | // The returned region is valid until the next call to Skip() or 126 | // until this object is destroyed, whichever occurs first. 127 | // 128 | // The returned region may be larger than Available() (for example 129 | // if this ByteSource is a view on a substring of a larger source). 130 | // The caller is responsible for ensuring that it only reads the 131 | // Available() bytes. 132 | virtual const char* Peek(size_t* len) = 0; 133 | 134 | // Skip the next n bytes. Invalidates any buffer returned by 135 | // a previous call to Peek(). 136 | // REQUIRES: Available() >= n 137 | virtual void Skip(size_t n) = 0; 138 | 139 | private: 140 | // No copying 141 | Source(const Source&); 142 | void operator=(const Source&); 143 | }; 144 | 145 | // A Source implementation that yields the contents of a flat array 146 | class ByteArraySource : public Source { 147 | public: 148 | ByteArraySource(const char* p, size_t n) : ptr_(p), left_(n) { } 149 | virtual ~ByteArraySource(); 150 | virtual size_t Available() const; 151 | virtual const char* Peek(size_t* len); 152 | virtual void Skip(size_t n); 153 | private: 154 | const char* ptr_; 155 | size_t left_; 156 | }; 157 | 158 | // A Sink implementation that writes to a flat array without any bound checks. 159 | class UncheckedByteArraySink : public Sink { 160 | public: 161 | explicit UncheckedByteArraySink(char* dest) : dest_(dest) { } 162 | virtual ~UncheckedByteArraySink(); 163 | virtual void Append(const char* data, size_t n); 164 | virtual char* GetAppendBuffer(size_t len, char* scratch); 165 | virtual char* GetAppendBufferVariable( 166 | size_t min_size, size_t desired_size_hint, char* scratch, 167 | size_t scratch_size, size_t* allocated_size); 168 | virtual void AppendAndTakeOwnership( 169 | char* bytes, size_t n, void (*deleter)(void*, const char*, size_t), 170 | void *deleter_arg); 171 | 172 | // Return the current output pointer so that a caller can see how 173 | // many bytes were produced. 174 | // Note: this is not a Sink method. 175 | char* CurrentDestination() const { return dest_; } 176 | private: 177 | char* dest_; 178 | }; 179 | 180 | } // namespace snappy 181 | 182 | #endif // THIRD_PARTY_SNAPPY_SNAPPY_SINKSOURCE_H_ 183 | -------------------------------------------------------------------------------- /benchmark/benchmark.js: -------------------------------------------------------------------------------- 1 | var util = require('util'); 2 | var zlib = require('zlib'); 3 | 4 | var benchmark = require('async-benchmark'); 5 | var bytes = require('bytes'); 6 | var chalk = require('chalk'); 7 | 8 | var snappy = require('../snappy'); 9 | var input = require('fs').readFileSync( 10 | require('path').join(__dirname, '../deps/snappy/snappy-1.1.4/snappy.cc') 11 | ); 12 | 13 | var round = function (number) { 14 | return Math.round(number * 100) / 100; 15 | }; 16 | var customGzip = function (data, callback) { 17 | var buffers = []; 18 | var size = 0; 19 | var gzip = new zlib.Gzip({ 20 | level: zlib.Z_BEST_SPEED, 21 | memLevel: zlib.Z_MAX_MEMLEVEL 22 | }); 23 | 24 | gzip.on('data', function (buffer) { 25 | buffers.push(buffer); 26 | size += buffer.length; 27 | }).on('end', function () { 28 | callback(null, Buffer.concat(buffers, size)); 29 | }); 30 | 31 | gzip.write(data); 32 | gzip.end(); 33 | }; 34 | var customGunzip = function (data, callback) { 35 | var buffers = []; 36 | var size = 0; 37 | var gunzip = new zlib.Gunzip(); 38 | 39 | gunzip.on('data', function (buffer) { 40 | buffers.push(buffer); 41 | size += buffer.length; 42 | }).on('end', function () { 43 | callback(null, Buffer.concat(buffers, size)); 44 | }); 45 | 46 | gunzip.write(data); 47 | gunzip.end(); 48 | }; 49 | var customDeflate = function (data, callback) { 50 | var buffers = []; 51 | var size = 0; 52 | var deflate = new zlib.Deflate({ 53 | level: zlib.Z_BEST_SPEED, 54 | memLevel: zlib.Z_MAX_MEMLEVEL 55 | }); 56 | 57 | deflate.on('data', function (buffer) { 58 | buffers.push(buffer); 59 | size += buffer.length; 60 | }).on('end', function () { 61 | callback(null, Buffer.concat(buffers, size)); 62 | }); 63 | 64 | deflate.write(data); 65 | deflate.end(); 66 | }; 67 | var customInflate = function (data, callback) { 68 | var buffers = []; 69 | var size = 0; 70 | var inflate = new zlib.Inflate(); 71 | 72 | inflate.on('data', function (buffer) { 73 | buffers.push(buffer); 74 | size += buffer.length; 75 | }).on('end', function () { 76 | callback(null, Buffer.concat(buffers, size)); 77 | }); 78 | 79 | inflate.write(data); 80 | inflate.end(); 81 | }; 82 | 83 | console.log(chalk.underline(util.format('input size %s', bytes(input.length)))); 84 | console.log(); 85 | require('run-series')([ 86 | function (done) { 87 | benchmark( 88 | 'snappy.compress()', 89 | snappy.compress.bind(snappy, input), 90 | function (err, event) { 91 | if (err) { 92 | throw err; 93 | } 94 | console.log(chalk.blue(event.target.toString())); 95 | snappy.compress(input, function (err, compressed) { 96 | if (err) { 97 | throw err; 98 | } 99 | var str = util.format( 100 | 'compressed size %s (%s%)', 101 | bytes(compressed.length), 102 | round(compressed.length / input.length * 100) 103 | ); 104 | console.log(chalk.blue(str)); 105 | done(); 106 | }); 107 | } 108 | ); 109 | }, 110 | function (done) { 111 | benchmark( 112 | 'zlib.gzip()', 113 | zlib.gzip.bind(zlib, input), 114 | function (err, event) { 115 | if (err) { 116 | throw err; 117 | } 118 | console.log(chalk.yellow(event.target.toString())); 119 | zlib.gzip(input, function (err, compressed) { 120 | if (err) { 121 | throw err; 122 | } 123 | var str = util.format( 124 | 'compressed size %s (%s%)', 125 | bytes(compressed.length), 126 | round(compressed.length / input.length * 100) 127 | ); 128 | console.log(chalk.yellow(str)); 129 | done(); 130 | }); 131 | } 132 | ); 133 | }, 134 | function (done) { 135 | benchmark( 136 | 'zlib.deflate()', 137 | zlib.deflate.bind(zlib, input), 138 | function (err, event) { 139 | if (err) { 140 | throw err; 141 | } 142 | console.log(chalk.white(event.target.toString())); 143 | zlib.deflate(input, function (err, compressed) { 144 | if (err) { 145 | throw err; 146 | } 147 | var str = util.format( 148 | 'compressed size %s (%s%)', 149 | bytes(compressed.length), 150 | round(compressed.length / input.length * 100) 151 | ); 152 | console.log(chalk.white(str)); 153 | done(); 154 | }); 155 | } 156 | ); 157 | }, 158 | function (done) { 159 | benchmark( 160 | 'zlib.Gzip with custom options', 161 | customGzip.bind(zlib, input), 162 | function (err, event) { 163 | if (err) { 164 | throw err; 165 | } 166 | console.log(chalk.magenta(event.target.toString())); 167 | customGzip(input, function (err, compressed) { 168 | if (err) { 169 | throw err; 170 | } 171 | var str = util.format( 172 | 'compressed size %s (%s%)', 173 | bytes(compressed.length), 174 | round(compressed.length / input.length * 100) 175 | ); 176 | console.log(chalk.magenta(str)); 177 | done(); 178 | }); 179 | } 180 | ); 181 | }, 182 | function (done) { 183 | benchmark( 184 | 'zlib.Deflate with custom options', 185 | customDeflate.bind(zlib, input), 186 | function (err, event) { 187 | if (err) { 188 | throw err; 189 | } 190 | console.log(chalk.green(event.target.toString())); 191 | customDeflate(input, function (err, compressed) { 192 | if (err) { 193 | throw err; 194 | } 195 | var str = util.format( 196 | 'compressed size %s (%s%)', 197 | bytes(compressed.length), 198 | round(compressed.length / input.length * 100) 199 | ); 200 | console.log(chalk.green(str)); 201 | console.log(); 202 | done(); 203 | }); 204 | } 205 | ); 206 | }, 207 | function (done) { 208 | snappy.compress(input, function (err, compressed) { 209 | if (err) { 210 | throw err; 211 | } 212 | benchmark( 213 | 'snappy.uncompress()', 214 | snappy.uncompress.bind(snappy, compressed), 215 | function (err, event) { 216 | if (err) { 217 | throw err; 218 | } 219 | console.log(chalk.blue(event.target.toString())); 220 | done(); 221 | } 222 | ); 223 | }); 224 | }, 225 | function (done) { 226 | zlib.gzip(input, function (err, compressed) { 227 | if (err) { 228 | throw err; 229 | } 230 | benchmark( 231 | 'zlib.gunzip()', 232 | zlib.gunzip.bind(zlib, compressed), 233 | function (err, event) { 234 | if (err) { 235 | throw err; 236 | } 237 | console.log(chalk.yellow(event.target.toString())); 238 | done(); 239 | } 240 | ); 241 | }); 242 | }, 243 | function (done) { 244 | zlib.deflate(input, function (err, compressed) { 245 | if (err) { 246 | throw err; 247 | } 248 | benchmark( 249 | 'zlib.inflate()', 250 | zlib.inflate.bind(zlib, compressed), 251 | function (err, event) { 252 | if (err) { 253 | throw err; 254 | } 255 | console.log(chalk.white(event.target.toString())); 256 | done(); 257 | } 258 | ); 259 | }); 260 | }, 261 | function (done) { 262 | customGzip(input, function (err, compressed) { 263 | if (err) { 264 | throw err; 265 | } 266 | benchmark( 267 | 'zlib.Gunzip with custom options', 268 | customGunzip.bind(zlib, compressed), 269 | function (err, event) { 270 | if (err) { 271 | throw err; 272 | } 273 | console.log(chalk.magenta(event.target.toString())); 274 | done(); 275 | } 276 | ); 277 | }); 278 | }, 279 | function (done) { 280 | customDeflate(input, function (err, compressed) { 281 | if (err) { 282 | throw err; 283 | } 284 | benchmark( 285 | 'zlib.Inflate with custom options', 286 | customInflate.bind(zlib, compressed), 287 | function (err, event) { 288 | if (err) { 289 | throw err; 290 | } 291 | console.log(chalk.green(event.target.toString())); 292 | done(); 293 | } 294 | ); 295 | }); 296 | } 297 | ]); 298 | -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.7/snappy-internal.h: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Google Inc. All Rights Reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of Google Inc. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | // 29 | // Internals shared between the Snappy implementation and its unittest. 30 | 31 | #ifndef THIRD_PARTY_SNAPPY_SNAPPY_INTERNAL_H_ 32 | #define THIRD_PARTY_SNAPPY_SNAPPY_INTERNAL_H_ 33 | 34 | #include "snappy-stubs-internal.h" 35 | 36 | namespace snappy { 37 | namespace internal { 38 | 39 | class WorkingMemory { 40 | public: 41 | WorkingMemory() : large_table_(NULL) { } 42 | ~WorkingMemory() { delete[] large_table_; } 43 | 44 | // Allocates and clears a hash table using memory in "*this", 45 | // stores the number of buckets in "*table_size" and returns a pointer to 46 | // the base of the hash table. 47 | uint16* GetHashTable(size_t input_size, int* table_size); 48 | 49 | private: 50 | uint16 small_table_[1<<10]; // 2KB 51 | uint16* large_table_; // Allocated only when needed 52 | 53 | // No copying 54 | WorkingMemory(const WorkingMemory&); 55 | void operator=(const WorkingMemory&); 56 | }; 57 | 58 | // Flat array compression that does not emit the "uncompressed length" 59 | // prefix. Compresses "input" string to the "*op" buffer. 60 | // 61 | // REQUIRES: "input_length <= kBlockSize" 62 | // REQUIRES: "op" points to an array of memory that is at least 63 | // "MaxCompressedLength(input_length)" in size. 64 | // REQUIRES: All elements in "table[0..table_size-1]" are initialized to zero. 65 | // REQUIRES: "table_size" is a power of two 66 | // 67 | // Returns an "end" pointer into "op" buffer. 68 | // "end - op" is the compressed size of "input". 69 | char* CompressFragment(const char* input, 70 | size_t input_length, 71 | char* op, 72 | uint16* table, 73 | const int table_size); 74 | 75 | // Find the largest n such that 76 | // 77 | // s1[0,n-1] == s2[0,n-1] 78 | // and n <= (s2_limit - s2). 79 | // 80 | // Return make_pair(n, n < 8). 81 | // Does not read *s2_limit or beyond. 82 | // Does not read *(s1 + (s2_limit - s2)) or beyond. 83 | // Requires that s2_limit >= s2. 84 | // 85 | // Separate implementation for 64-bit, little-endian cpus. 86 | #if !defined(SNAPPY_IS_BIG_ENDIAN) && \ 87 | (defined(ARCH_K8) || defined(ARCH_PPC) || defined(ARCH_ARM)) 88 | static inline std::pair FindMatchLength(const char* s1, 89 | const char* s2, 90 | const char* s2_limit) { 91 | assert(s2_limit >= s2); 92 | size_t matched = 0; 93 | 94 | // This block isn't necessary for correctness; we could just start looping 95 | // immediately. As an optimization though, it is useful. It creates some not 96 | // uncommon code paths that determine, without extra effort, whether the match 97 | // length is less than 8. In short, we are hoping to avoid a conditional 98 | // branch, and perhaps get better code layout from the C++ compiler. 99 | if (SNAPPY_PREDICT_TRUE(s2 <= s2_limit - 8)) { 100 | uint64 a1 = UNALIGNED_LOAD64(s1); 101 | uint64 a2 = UNALIGNED_LOAD64(s2); 102 | if (a1 != a2) { 103 | return std::pair(Bits::FindLSBSetNonZero64(a1 ^ a2) >> 3, 104 | true); 105 | } else { 106 | matched = 8; 107 | s2 += 8; 108 | } 109 | } 110 | 111 | // Find out how long the match is. We loop over the data 64 bits at a 112 | // time until we find a 64-bit block that doesn't match; then we find 113 | // the first non-matching bit and use that to calculate the total 114 | // length of the match. 115 | while (SNAPPY_PREDICT_TRUE(s2 <= s2_limit - 8)) { 116 | if (UNALIGNED_LOAD64(s2) == UNALIGNED_LOAD64(s1 + matched)) { 117 | s2 += 8; 118 | matched += 8; 119 | } else { 120 | uint64 x = UNALIGNED_LOAD64(s2) ^ UNALIGNED_LOAD64(s1 + matched); 121 | int matching_bits = Bits::FindLSBSetNonZero64(x); 122 | matched += matching_bits >> 3; 123 | assert(matched >= 8); 124 | return std::pair(matched, false); 125 | } 126 | } 127 | while (SNAPPY_PREDICT_TRUE(s2 < s2_limit)) { 128 | if (s1[matched] == *s2) { 129 | ++s2; 130 | ++matched; 131 | } else { 132 | return std::pair(matched, matched < 8); 133 | } 134 | } 135 | return std::pair(matched, matched < 8); 136 | } 137 | #else 138 | static inline std::pair FindMatchLength(const char* s1, 139 | const char* s2, 140 | const char* s2_limit) { 141 | // Implementation based on the x86-64 version, above. 142 | assert(s2_limit >= s2); 143 | int matched = 0; 144 | 145 | while (s2 <= s2_limit - 4 && 146 | UNALIGNED_LOAD32(s2) == UNALIGNED_LOAD32(s1 + matched)) { 147 | s2 += 4; 148 | matched += 4; 149 | } 150 | if (LittleEndian::IsLittleEndian() && s2 <= s2_limit - 4) { 151 | uint32 x = UNALIGNED_LOAD32(s2) ^ UNALIGNED_LOAD32(s1 + matched); 152 | int matching_bits = Bits::FindLSBSetNonZero(x); 153 | matched += matching_bits >> 3; 154 | } else { 155 | while ((s2 < s2_limit) && (s1[matched] == *s2)) { 156 | ++s2; 157 | ++matched; 158 | } 159 | } 160 | return std::pair(matched, matched < 8); 161 | } 162 | #endif 163 | 164 | // Lookup tables for decompression code. Give --snappy_dump_decompression_table 165 | // to the unit test to recompute char_table. 166 | 167 | enum { 168 | LITERAL = 0, 169 | COPY_1_BYTE_OFFSET = 1, // 3 bit length + 3 bits of offset in opcode 170 | COPY_2_BYTE_OFFSET = 2, 171 | COPY_4_BYTE_OFFSET = 3 172 | }; 173 | static const int kMaximumTagLength = 5; // COPY_4_BYTE_OFFSET plus the actual offset. 174 | 175 | // Data stored per entry in lookup table: 176 | // Range Bits-used Description 177 | // ------------------------------------ 178 | // 1..64 0..7 Literal/copy length encoded in opcode byte 179 | // 0..7 8..10 Copy offset encoded in opcode byte / 256 180 | // 0..4 11..13 Extra bytes after opcode 181 | // 182 | // We use eight bits for the length even though 7 would have sufficed 183 | // because of efficiency reasons: 184 | // (1) Extracting a byte is faster than a bit-field 185 | // (2) It properly aligns copy offset so we do not need a <<8 186 | static const uint16 char_table[256] = { 187 | 0x0001, 0x0804, 0x1001, 0x2001, 0x0002, 0x0805, 0x1002, 0x2002, 188 | 0x0003, 0x0806, 0x1003, 0x2003, 0x0004, 0x0807, 0x1004, 0x2004, 189 | 0x0005, 0x0808, 0x1005, 0x2005, 0x0006, 0x0809, 0x1006, 0x2006, 190 | 0x0007, 0x080a, 0x1007, 0x2007, 0x0008, 0x080b, 0x1008, 0x2008, 191 | 0x0009, 0x0904, 0x1009, 0x2009, 0x000a, 0x0905, 0x100a, 0x200a, 192 | 0x000b, 0x0906, 0x100b, 0x200b, 0x000c, 0x0907, 0x100c, 0x200c, 193 | 0x000d, 0x0908, 0x100d, 0x200d, 0x000e, 0x0909, 0x100e, 0x200e, 194 | 0x000f, 0x090a, 0x100f, 0x200f, 0x0010, 0x090b, 0x1010, 0x2010, 195 | 0x0011, 0x0a04, 0x1011, 0x2011, 0x0012, 0x0a05, 0x1012, 0x2012, 196 | 0x0013, 0x0a06, 0x1013, 0x2013, 0x0014, 0x0a07, 0x1014, 0x2014, 197 | 0x0015, 0x0a08, 0x1015, 0x2015, 0x0016, 0x0a09, 0x1016, 0x2016, 198 | 0x0017, 0x0a0a, 0x1017, 0x2017, 0x0018, 0x0a0b, 0x1018, 0x2018, 199 | 0x0019, 0x0b04, 0x1019, 0x2019, 0x001a, 0x0b05, 0x101a, 0x201a, 200 | 0x001b, 0x0b06, 0x101b, 0x201b, 0x001c, 0x0b07, 0x101c, 0x201c, 201 | 0x001d, 0x0b08, 0x101d, 0x201d, 0x001e, 0x0b09, 0x101e, 0x201e, 202 | 0x001f, 0x0b0a, 0x101f, 0x201f, 0x0020, 0x0b0b, 0x1020, 0x2020, 203 | 0x0021, 0x0c04, 0x1021, 0x2021, 0x0022, 0x0c05, 0x1022, 0x2022, 204 | 0x0023, 0x0c06, 0x1023, 0x2023, 0x0024, 0x0c07, 0x1024, 0x2024, 205 | 0x0025, 0x0c08, 0x1025, 0x2025, 0x0026, 0x0c09, 0x1026, 0x2026, 206 | 0x0027, 0x0c0a, 0x1027, 0x2027, 0x0028, 0x0c0b, 0x1028, 0x2028, 207 | 0x0029, 0x0d04, 0x1029, 0x2029, 0x002a, 0x0d05, 0x102a, 0x202a, 208 | 0x002b, 0x0d06, 0x102b, 0x202b, 0x002c, 0x0d07, 0x102c, 0x202c, 209 | 0x002d, 0x0d08, 0x102d, 0x202d, 0x002e, 0x0d09, 0x102e, 0x202e, 210 | 0x002f, 0x0d0a, 0x102f, 0x202f, 0x0030, 0x0d0b, 0x1030, 0x2030, 211 | 0x0031, 0x0e04, 0x1031, 0x2031, 0x0032, 0x0e05, 0x1032, 0x2032, 212 | 0x0033, 0x0e06, 0x1033, 0x2033, 0x0034, 0x0e07, 0x1034, 0x2034, 213 | 0x0035, 0x0e08, 0x1035, 0x2035, 0x0036, 0x0e09, 0x1036, 0x2036, 214 | 0x0037, 0x0e0a, 0x1037, 0x2037, 0x0038, 0x0e0b, 0x1038, 0x2038, 215 | 0x0039, 0x0f04, 0x1039, 0x2039, 0x003a, 0x0f05, 0x103a, 0x203a, 216 | 0x003b, 0x0f06, 0x103b, 0x203b, 0x003c, 0x0f07, 0x103c, 0x203c, 217 | 0x0801, 0x0f08, 0x103d, 0x203d, 0x1001, 0x0f09, 0x103e, 0x203e, 218 | 0x1801, 0x0f0a, 0x103f, 0x203f, 0x2001, 0x0f0b, 0x1040, 0x2040 219 | }; 220 | 221 | } // end namespace internal 222 | } // end namespace snappy 223 | 224 | #endif // THIRD_PARTY_SNAPPY_SNAPPY_INTERNAL_H_ 225 | -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.7/snappy.h: -------------------------------------------------------------------------------- 1 | // Copyright 2005 and onwards Google Inc. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of Google Inc. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | // 29 | // A light-weight compression algorithm. It is designed for speed of 30 | // compression and decompression, rather than for the utmost in space 31 | // savings. 32 | // 33 | // For getting better compression ratios when you are compressing data 34 | // with long repeated sequences or compressing data that is similar to 35 | // other data, while still compressing fast, you might look at first 36 | // using BMDiff and then compressing the output of BMDiff with 37 | // Snappy. 38 | 39 | #ifndef THIRD_PARTY_SNAPPY_SNAPPY_H__ 40 | #define THIRD_PARTY_SNAPPY_SNAPPY_H__ 41 | 42 | #include 43 | #include 44 | 45 | #include "snappy-stubs-public.h" 46 | 47 | namespace snappy { 48 | class Source; 49 | class Sink; 50 | 51 | // ------------------------------------------------------------------------ 52 | // Generic compression/decompression routines. 53 | // ------------------------------------------------------------------------ 54 | 55 | // Compress the bytes read from "*source" and append to "*sink". Return the 56 | // number of bytes written. 57 | size_t Compress(Source* source, Sink* sink); 58 | 59 | // Find the uncompressed length of the given stream, as given by the header. 60 | // Note that the true length could deviate from this; the stream could e.g. 61 | // be truncated. 62 | // 63 | // Also note that this leaves "*source" in a state that is unsuitable for 64 | // further operations, such as RawUncompress(). You will need to rewind 65 | // or recreate the source yourself before attempting any further calls. 66 | bool GetUncompressedLength(Source* source, uint32* result); 67 | 68 | // ------------------------------------------------------------------------ 69 | // Higher-level string based routines (should be sufficient for most users) 70 | // ------------------------------------------------------------------------ 71 | 72 | // Sets "*output" to the compressed version of "input[0,input_length-1]". 73 | // Original contents of *output are lost. 74 | // 75 | // REQUIRES: "input[]" is not an alias of "*output". 76 | size_t Compress(const char* input, size_t input_length, string* output); 77 | 78 | // Decompresses "compressed[0,compressed_length-1]" to "*uncompressed". 79 | // Original contents of "*uncompressed" are lost. 80 | // 81 | // REQUIRES: "compressed[]" is not an alias of "*uncompressed". 82 | // 83 | // returns false if the message is corrupted and could not be decompressed 84 | bool Uncompress(const char* compressed, size_t compressed_length, 85 | string* uncompressed); 86 | 87 | // Decompresses "compressed" to "*uncompressed". 88 | // 89 | // returns false if the message is corrupted and could not be decompressed 90 | bool Uncompress(Source* compressed, Sink* uncompressed); 91 | 92 | // This routine uncompresses as much of the "compressed" as possible 93 | // into sink. It returns the number of valid bytes added to sink 94 | // (extra invalid bytes may have been added due to errors; the caller 95 | // should ignore those). The emitted data typically has length 96 | // GetUncompressedLength(), but may be shorter if an error is 97 | // encountered. 98 | size_t UncompressAsMuchAsPossible(Source* compressed, Sink* uncompressed); 99 | 100 | // ------------------------------------------------------------------------ 101 | // Lower-level character array based routines. May be useful for 102 | // efficiency reasons in certain circumstances. 103 | // ------------------------------------------------------------------------ 104 | 105 | // REQUIRES: "compressed" must point to an area of memory that is at 106 | // least "MaxCompressedLength(input_length)" bytes in length. 107 | // 108 | // Takes the data stored in "input[0..input_length]" and stores 109 | // it in the array pointed to by "compressed". 110 | // 111 | // "*compressed_length" is set to the length of the compressed output. 112 | // 113 | // Example: 114 | // char* output = new char[snappy::MaxCompressedLength(input_length)]; 115 | // size_t output_length; 116 | // RawCompress(input, input_length, output, &output_length); 117 | // ... Process(output, output_length) ... 118 | // delete [] output; 119 | void RawCompress(const char* input, 120 | size_t input_length, 121 | char* compressed, 122 | size_t* compressed_length); 123 | 124 | // Given data in "compressed[0..compressed_length-1]" generated by 125 | // calling the Snappy::Compress routine, this routine 126 | // stores the uncompressed data to 127 | // uncompressed[0..GetUncompressedLength(compressed)-1] 128 | // returns false if the message is corrupted and could not be decrypted 129 | bool RawUncompress(const char* compressed, size_t compressed_length, 130 | char* uncompressed); 131 | 132 | // Given data from the byte source 'compressed' generated by calling 133 | // the Snappy::Compress routine, this routine stores the uncompressed 134 | // data to 135 | // uncompressed[0..GetUncompressedLength(compressed,compressed_length)-1] 136 | // returns false if the message is corrupted and could not be decrypted 137 | bool RawUncompress(Source* compressed, char* uncompressed); 138 | 139 | // Given data in "compressed[0..compressed_length-1]" generated by 140 | // calling the Snappy::Compress routine, this routine 141 | // stores the uncompressed data to the iovec "iov". The number of physical 142 | // buffers in "iov" is given by iov_cnt and their cumulative size 143 | // must be at least GetUncompressedLength(compressed). The individual buffers 144 | // in "iov" must not overlap with each other. 145 | // 146 | // returns false if the message is corrupted and could not be decrypted 147 | bool RawUncompressToIOVec(const char* compressed, size_t compressed_length, 148 | const struct iovec* iov, size_t iov_cnt); 149 | 150 | // Given data from the byte source 'compressed' generated by calling 151 | // the Snappy::Compress routine, this routine stores the uncompressed 152 | // data to the iovec "iov". The number of physical 153 | // buffers in "iov" is given by iov_cnt and their cumulative size 154 | // must be at least GetUncompressedLength(compressed). The individual buffers 155 | // in "iov" must not overlap with each other. 156 | // 157 | // returns false if the message is corrupted and could not be decrypted 158 | bool RawUncompressToIOVec(Source* compressed, const struct iovec* iov, 159 | size_t iov_cnt); 160 | 161 | // Returns the maximal size of the compressed representation of 162 | // input data that is "source_bytes" bytes in length; 163 | size_t MaxCompressedLength(size_t source_bytes); 164 | 165 | // REQUIRES: "compressed[]" was produced by RawCompress() or Compress() 166 | // Returns true and stores the length of the uncompressed data in 167 | // *result normally. Returns false on parsing error. 168 | // This operation takes O(1) time. 169 | bool GetUncompressedLength(const char* compressed, size_t compressed_length, 170 | size_t* result); 171 | 172 | // Returns true iff the contents of "compressed[]" can be uncompressed 173 | // successfully. Does not return the uncompressed data. Takes 174 | // time proportional to compressed_length, but is usually at least 175 | // a factor of four faster than actual decompression. 176 | bool IsValidCompressedBuffer(const char* compressed, 177 | size_t compressed_length); 178 | 179 | // Returns true iff the contents of "compressed" can be uncompressed 180 | // successfully. Does not return the uncompressed data. Takes 181 | // time proportional to *compressed length, but is usually at least 182 | // a factor of four faster than actual decompression. 183 | // On success, consumes all of *compressed. On failure, consumes an 184 | // unspecified prefix of *compressed. 185 | bool IsValidCompressed(Source* compressed); 186 | 187 | // The size of a compression block. Note that many parts of the compression 188 | // code assumes that kBlockSize <= 65536; in particular, the hash table 189 | // can only store 16-bit offsets, and EmitCopy() also assumes the offset 190 | // is 65535 bytes or less. Note also that if you change this, it will 191 | // affect the framing format (see framing_format.txt). 192 | // 193 | // Note that there might be older data around that is compressed with larger 194 | // block sizes, so the decompression code should not rely on the 195 | // non-existence of long backreferences. 196 | static const int kBlockLog = 16; 197 | static const size_t kBlockSize = 1 << kBlockLog; 198 | 199 | static const int kMaxHashTableBits = 14; 200 | static const size_t kMaxHashTableSize = 1 << kMaxHashTableBits; 201 | } // end namespace snappy 202 | 203 | #endif // THIRD_PARTY_SNAPPY_SNAPPY_H__ 204 | -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.7/snappy-test.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. All Rights Reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of Google Inc. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | // 29 | // Various stubs for the unit tests for the open-source version of Snappy. 30 | 31 | #ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_TEST_H_ 32 | #define THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_TEST_H_ 33 | 34 | #include 35 | #include 36 | 37 | #include "snappy-stubs-internal.h" 38 | 39 | #include 40 | #include 41 | 42 | #ifdef HAVE_SYS_MMAN_H 43 | #include 44 | #endif 45 | 46 | #ifdef HAVE_SYS_RESOURCE_H 47 | #include 48 | #endif 49 | 50 | #ifdef HAVE_SYS_TIME_H 51 | #include 52 | #endif 53 | 54 | #ifdef HAVE_WINDOWS_H 55 | #include 56 | #endif 57 | 58 | #include 59 | 60 | #ifdef HAVE_GTEST 61 | 62 | #include 63 | #undef TYPED_TEST 64 | #define TYPED_TEST TEST 65 | #define INIT_GTEST(argc, argv) ::testing::InitGoogleTest(argc, *argv) 66 | 67 | #else 68 | 69 | // Stubs for if the user doesn't have Google Test installed. 70 | 71 | #define TEST(test_case, test_subcase) \ 72 | void Test_ ## test_case ## _ ## test_subcase() 73 | #define INIT_GTEST(argc, argv) 74 | 75 | #define TYPED_TEST TEST 76 | #define EXPECT_EQ CHECK_EQ 77 | #define EXPECT_NE CHECK_NE 78 | #define EXPECT_FALSE(cond) CHECK(!(cond)) 79 | 80 | #endif 81 | 82 | #ifdef HAVE_GFLAGS 83 | 84 | #include 85 | 86 | // This is tricky; both gflags and Google Test want to look at the command line 87 | // arguments. Google Test seems to be the most happy with unknown arguments, 88 | // though, so we call it first and hope for the best. 89 | #define InitGoogle(argv0, argc, argv, remove_flags) \ 90 | INIT_GTEST(argc, argv); \ 91 | google::ParseCommandLineFlags(argc, argv, remove_flags); 92 | 93 | #else 94 | 95 | // If we don't have the gflags package installed, these can only be 96 | // changed at compile time. 97 | #define DEFINE_int32(flag_name, default_value, description) \ 98 | static int FLAGS_ ## flag_name = default_value; 99 | 100 | #define InitGoogle(argv0, argc, argv, remove_flags) \ 101 | INIT_GTEST(argc, argv) 102 | 103 | #endif 104 | 105 | #ifdef HAVE_LIBZ 106 | #include "zlib.h" 107 | #endif 108 | 109 | #ifdef HAVE_LIBLZO2 110 | #include "lzo/lzo1x.h" 111 | #endif 112 | 113 | namespace { 114 | 115 | namespace file { 116 | int Defaults() { return 0; } 117 | 118 | class DummyStatus { 119 | public: 120 | void CheckSuccess() { } 121 | }; 122 | 123 | DummyStatus GetContents( 124 | const std::string& filename, std::string* data, int unused) { 125 | FILE* fp = fopen(filename.c_str(), "rb"); 126 | if (fp == NULL) { 127 | perror(filename.c_str()); 128 | exit(1); 129 | } 130 | 131 | data->clear(); 132 | while (!feof(fp)) { 133 | char buf[4096]; 134 | size_t ret = fread(buf, 1, 4096, fp); 135 | if (ret == 0 && ferror(fp)) { 136 | perror("fread"); 137 | exit(1); 138 | } 139 | data->append(std::string(buf, ret)); 140 | } 141 | 142 | fclose(fp); 143 | 144 | return DummyStatus(); 145 | } 146 | 147 | inline DummyStatus SetContents( 148 | const std::string& filename, const std::string& str, int unused) { 149 | FILE* fp = fopen(filename.c_str(), "wb"); 150 | if (fp == NULL) { 151 | perror(filename.c_str()); 152 | exit(1); 153 | } 154 | 155 | int ret = fwrite(str.data(), str.size(), 1, fp); 156 | if (ret != 1) { 157 | perror("fwrite"); 158 | exit(1); 159 | } 160 | 161 | fclose(fp); 162 | 163 | return DummyStatus(); 164 | } 165 | } // namespace file 166 | 167 | } // namespace 168 | 169 | namespace snappy { 170 | 171 | #define FLAGS_test_random_seed 301 172 | typedef string TypeParam; 173 | 174 | void Test_CorruptedTest_VerifyCorrupted(); 175 | void Test_Snappy_SimpleTests(); 176 | void Test_Snappy_MaxBlowup(); 177 | void Test_Snappy_RandomData(); 178 | void Test_Snappy_FourByteOffset(); 179 | void Test_SnappyCorruption_TruncatedVarint(); 180 | void Test_SnappyCorruption_UnterminatedVarint(); 181 | void Test_SnappyCorruption_OverflowingVarint(); 182 | void Test_Snappy_ReadPastEndOfBuffer(); 183 | void Test_Snappy_FindMatchLength(); 184 | void Test_Snappy_FindMatchLengthRandom(); 185 | 186 | string ReadTestDataFile(const string& base, size_t size_limit); 187 | 188 | string ReadTestDataFile(const string& base); 189 | 190 | // A sprintf() variant that returns a std::string. 191 | // Not safe for general use due to truncation issues. 192 | string StringPrintf(const char* format, ...); 193 | 194 | // A simple, non-cryptographically-secure random generator. 195 | class ACMRandom { 196 | public: 197 | explicit ACMRandom(uint32 seed) : seed_(seed) {} 198 | 199 | int32 Next(); 200 | 201 | int32 Uniform(int32 n) { 202 | return Next() % n; 203 | } 204 | uint8 Rand8() { 205 | return static_cast((Next() >> 1) & 0x000000ff); 206 | } 207 | bool OneIn(int X) { return Uniform(X) == 0; } 208 | 209 | // Skewed: pick "base" uniformly from range [0,max_log] and then 210 | // return "base" random bits. The effect is to pick a number in the 211 | // range [0,2^max_log-1] with bias towards smaller numbers. 212 | int32 Skewed(int max_log); 213 | 214 | private: 215 | static const uint32 M = 2147483647L; // 2^31-1 216 | uint32 seed_; 217 | }; 218 | 219 | inline int32 ACMRandom::Next() { 220 | static const uint64 A = 16807; // bits 14, 8, 7, 5, 2, 1, 0 221 | // We are computing 222 | // seed_ = (seed_ * A) % M, where M = 2^31-1 223 | // 224 | // seed_ must not be zero or M, or else all subsequent computed values 225 | // will be zero or M respectively. For all other values, seed_ will end 226 | // up cycling through every number in [1,M-1] 227 | uint64 product = seed_ * A; 228 | 229 | // Compute (product % M) using the fact that ((x << 31) % M) == x. 230 | seed_ = (product >> 31) + (product & M); 231 | // The first reduction may overflow by 1 bit, so we may need to repeat. 232 | // mod == M is not possible; using > allows the faster sign-bit-based test. 233 | if (seed_ > M) { 234 | seed_ -= M; 235 | } 236 | return seed_; 237 | } 238 | 239 | inline int32 ACMRandom::Skewed(int max_log) { 240 | const int32 base = (Next() - 1) % (max_log+1); 241 | return (Next() - 1) & ((1u << base)-1); 242 | } 243 | 244 | // A wall-time clock. This stub is not super-accurate, nor resistant to the 245 | // system time changing. 246 | class CycleTimer { 247 | public: 248 | CycleTimer() : real_time_us_(0) {} 249 | 250 | void Start() { 251 | #ifdef WIN32 252 | QueryPerformanceCounter(&start_); 253 | #else 254 | gettimeofday(&start_, NULL); 255 | #endif 256 | } 257 | 258 | void Stop() { 259 | #ifdef WIN32 260 | LARGE_INTEGER stop; 261 | LARGE_INTEGER frequency; 262 | QueryPerformanceCounter(&stop); 263 | QueryPerformanceFrequency(&frequency); 264 | 265 | double elapsed = static_cast(stop.QuadPart - start_.QuadPart) / 266 | frequency.QuadPart; 267 | real_time_us_ += elapsed * 1e6 + 0.5; 268 | #else 269 | struct timeval stop; 270 | gettimeofday(&stop, NULL); 271 | 272 | real_time_us_ += 1000000 * (stop.tv_sec - start_.tv_sec); 273 | real_time_us_ += (stop.tv_usec - start_.tv_usec); 274 | #endif 275 | } 276 | 277 | double Get() { 278 | return real_time_us_ * 1e-6; 279 | } 280 | 281 | private: 282 | int64 real_time_us_; 283 | #ifdef WIN32 284 | LARGE_INTEGER start_; 285 | #else 286 | struct timeval start_; 287 | #endif 288 | }; 289 | 290 | // Minimalistic microbenchmark framework. 291 | 292 | typedef void (*BenchmarkFunction)(int, int); 293 | 294 | class Benchmark { 295 | public: 296 | Benchmark(const string& name, BenchmarkFunction function) : 297 | name_(name), function_(function) {} 298 | 299 | Benchmark* DenseRange(int start, int stop) { 300 | start_ = start; 301 | stop_ = stop; 302 | return this; 303 | } 304 | 305 | void Run(); 306 | 307 | private: 308 | const string name_; 309 | const BenchmarkFunction function_; 310 | int start_, stop_; 311 | }; 312 | #define BENCHMARK(benchmark_name) \ 313 | Benchmark* Benchmark_ ## benchmark_name = \ 314 | (new Benchmark(#benchmark_name, benchmark_name)) 315 | 316 | extern Benchmark* Benchmark_BM_UFlat; 317 | extern Benchmark* Benchmark_BM_UIOVec; 318 | extern Benchmark* Benchmark_BM_UValidate; 319 | extern Benchmark* Benchmark_BM_ZFlat; 320 | 321 | void ResetBenchmarkTiming(); 322 | void StartBenchmarkTiming(); 323 | void StopBenchmarkTiming(); 324 | void SetBenchmarkLabel(const string& str); 325 | void SetBenchmarkBytesProcessed(int64 bytes); 326 | 327 | #ifdef HAVE_LIBZ 328 | 329 | // Object-oriented wrapper around zlib. 330 | class ZLib { 331 | public: 332 | ZLib(); 333 | ~ZLib(); 334 | 335 | // Wipe a ZLib object to a virgin state. This differs from Reset() 336 | // in that it also breaks any state. 337 | void Reinit(); 338 | 339 | // Call this to make a zlib buffer as good as new. Here's the only 340 | // case where they differ: 341 | // CompressChunk(a); CompressChunk(b); CompressChunkDone(); vs 342 | // CompressChunk(a); Reset(); CompressChunk(b); CompressChunkDone(); 343 | // You'll want to use Reset(), then, when you interrupt a compress 344 | // (or uncompress) in the middle of a chunk and want to start over. 345 | void Reset(); 346 | 347 | // According to the zlib manual, when you Compress, the destination 348 | // buffer must have size at least src + .1%*src + 12. This function 349 | // helps you calculate that. Augment this to account for a potential 350 | // gzip header and footer, plus a few bytes of slack. 351 | static int MinCompressbufSize(int uncompress_size) { 352 | return uncompress_size + uncompress_size/1000 + 40; 353 | } 354 | 355 | // Compresses the source buffer into the destination buffer. 356 | // sourceLen is the byte length of the source buffer. 357 | // Upon entry, destLen is the total size of the destination buffer, 358 | // which must be of size at least MinCompressbufSize(sourceLen). 359 | // Upon exit, destLen is the actual size of the compressed buffer. 360 | // 361 | // This function can be used to compress a whole file at once if the 362 | // input file is mmap'ed. 363 | // 364 | // Returns Z_OK if success, Z_MEM_ERROR if there was not 365 | // enough memory, Z_BUF_ERROR if there was not enough room in the 366 | // output buffer. Note that if the output buffer is exactly the same 367 | // size as the compressed result, we still return Z_BUF_ERROR. 368 | // (check CL#1936076) 369 | int Compress(Bytef *dest, uLongf *destLen, 370 | const Bytef *source, uLong sourceLen); 371 | 372 | // Uncompresses the source buffer into the destination buffer. 373 | // The destination buffer must be long enough to hold the entire 374 | // decompressed contents. 375 | // 376 | // Returns Z_OK on success, otherwise, it returns a zlib error code. 377 | int Uncompress(Bytef *dest, uLongf *destLen, 378 | const Bytef *source, uLong sourceLen); 379 | 380 | // Uncompress data one chunk at a time -- ie you can call this 381 | // more than once. To get this to work you need to call per-chunk 382 | // and "done" routines. 383 | // 384 | // Returns Z_OK if success, Z_MEM_ERROR if there was not 385 | // enough memory, Z_BUF_ERROR if there was not enough room in the 386 | // output buffer. 387 | 388 | int UncompressAtMost(Bytef *dest, uLongf *destLen, 389 | const Bytef *source, uLong *sourceLen); 390 | 391 | // Checks gzip footer information, as needed. Mostly this just 392 | // makes sure the checksums match. Whenever you call this, it 393 | // will assume the last 8 bytes from the previous UncompressChunk 394 | // call are the footer. Returns true iff everything looks ok. 395 | bool UncompressChunkDone(); 396 | 397 | private: 398 | int InflateInit(); // sets up the zlib inflate structure 399 | int DeflateInit(); // sets up the zlib deflate structure 400 | 401 | // These init the zlib data structures for compressing/uncompressing 402 | int CompressInit(Bytef *dest, uLongf *destLen, 403 | const Bytef *source, uLong *sourceLen); 404 | int UncompressInit(Bytef *dest, uLongf *destLen, 405 | const Bytef *source, uLong *sourceLen); 406 | // Initialization method to be called if we hit an error while 407 | // uncompressing. On hitting an error, call this method before 408 | // returning the error. 409 | void UncompressErrorInit(); 410 | 411 | // Helper function for Compress 412 | int CompressChunkOrAll(Bytef *dest, uLongf *destLen, 413 | const Bytef *source, uLong sourceLen, 414 | int flush_mode); 415 | int CompressAtMostOrAll(Bytef *dest, uLongf *destLen, 416 | const Bytef *source, uLong *sourceLen, 417 | int flush_mode); 418 | 419 | // Likewise for UncompressAndUncompressChunk 420 | int UncompressChunkOrAll(Bytef *dest, uLongf *destLen, 421 | const Bytef *source, uLong sourceLen, 422 | int flush_mode); 423 | 424 | int UncompressAtMostOrAll(Bytef *dest, uLongf *destLen, 425 | const Bytef *source, uLong *sourceLen, 426 | int flush_mode); 427 | 428 | // Initialization method to be called if we hit an error while 429 | // compressing. On hitting an error, call this method before 430 | // returning the error. 431 | void CompressErrorInit(); 432 | 433 | int compression_level_; // compression level 434 | int window_bits_; // log base 2 of the window size used in compression 435 | int mem_level_; // specifies the amount of memory to be used by 436 | // compressor (1-9) 437 | z_stream comp_stream_; // Zlib stream data structure 438 | bool comp_init_; // True if we have initialized comp_stream_ 439 | z_stream uncomp_stream_; // Zlib stream data structure 440 | bool uncomp_init_; // True if we have initialized uncomp_stream_ 441 | 442 | // These are used only with chunked compression. 443 | bool first_chunk_; // true if we need to emit headers with this chunk 444 | }; 445 | 446 | #endif // HAVE_LIBZ 447 | 448 | } // namespace snappy 449 | 450 | DECLARE_bool(run_microbenchmarks); 451 | 452 | static inline void RunSpecifiedBenchmarks() { 453 | if (!FLAGS_run_microbenchmarks) { 454 | return; 455 | } 456 | 457 | fprintf(stderr, "Running microbenchmarks.\n"); 458 | #ifndef NDEBUG 459 | fprintf(stderr, "WARNING: Compiled with assertions enabled, will be slow.\n"); 460 | #endif 461 | #ifndef __OPTIMIZE__ 462 | fprintf(stderr, "WARNING: Compiled without optimization, will be slow.\n"); 463 | #endif 464 | fprintf(stderr, "Benchmark Time(ns) CPU(ns) Iterations\n"); 465 | fprintf(stderr, "---------------------------------------------------\n"); 466 | 467 | snappy::Benchmark_BM_UFlat->Run(); 468 | snappy::Benchmark_BM_UIOVec->Run(); 469 | snappy::Benchmark_BM_UValidate->Run(); 470 | snappy::Benchmark_BM_ZFlat->Run(); 471 | 472 | fprintf(stderr, "\n"); 473 | } 474 | 475 | #ifndef HAVE_GTEST 476 | 477 | static inline int RUN_ALL_TESTS() { 478 | fprintf(stderr, "Running correctness tests.\n"); 479 | snappy::Test_CorruptedTest_VerifyCorrupted(); 480 | snappy::Test_Snappy_SimpleTests(); 481 | snappy::Test_Snappy_MaxBlowup(); 482 | snappy::Test_Snappy_RandomData(); 483 | snappy::Test_Snappy_FourByteOffset(); 484 | snappy::Test_SnappyCorruption_TruncatedVarint(); 485 | snappy::Test_SnappyCorruption_UnterminatedVarint(); 486 | snappy::Test_SnappyCorruption_OverflowingVarint(); 487 | snappy::Test_Snappy_ReadPastEndOfBuffer(); 488 | snappy::Test_Snappy_FindMatchLength(); 489 | snappy::Test_Snappy_FindMatchLengthRandom(); 490 | fprintf(stderr, "All tests passed.\n"); 491 | 492 | return 0; 493 | } 494 | 495 | #endif // HAVE_GTEST 496 | 497 | // For main(). 498 | namespace snappy { 499 | 500 | // Logging. 501 | 502 | #define LOG(level) LogMessage() 503 | #define VLOG(level) true ? (void)0 : \ 504 | snappy::LogMessageVoidify() & snappy::LogMessage() 505 | 506 | class LogMessage { 507 | public: 508 | LogMessage() { } 509 | ~LogMessage() { 510 | std::cerr << std::endl; 511 | } 512 | 513 | LogMessage& operator<<(const std::string& msg) { 514 | std::cerr << msg; 515 | return *this; 516 | } 517 | LogMessage& operator<<(int x) { 518 | std::cerr << x; 519 | return *this; 520 | } 521 | }; 522 | 523 | // Asserts, both versions activated in debug mode only, 524 | // and ones that are always active. 525 | 526 | #define CRASH_UNLESS(condition) \ 527 | SNAPPY_PREDICT_TRUE(condition) ? (void)0 : \ 528 | snappy::LogMessageVoidify() & snappy::LogMessageCrash() 529 | 530 | #ifdef _MSC_VER 531 | // ~LogMessageCrash calls abort() and therefore never exits. This is by design 532 | // so temporarily disable warning C4722. 533 | #pragma warning(push) 534 | #pragma warning(disable:4722) 535 | #endif 536 | 537 | class LogMessageCrash : public LogMessage { 538 | public: 539 | LogMessageCrash() { } 540 | ~LogMessageCrash() { 541 | std::cerr << std::endl; 542 | abort(); 543 | } 544 | }; 545 | 546 | #ifdef _MSC_VER 547 | #pragma warning(pop) 548 | #endif 549 | 550 | // This class is used to explicitly ignore values in the conditional 551 | // logging macros. This avoids compiler warnings like "value computed 552 | // is not used" and "statement has no effect". 553 | 554 | class LogMessageVoidify { 555 | public: 556 | LogMessageVoidify() { } 557 | // This has to be an operator with a precedence lower than << but 558 | // higher than ?: 559 | void operator&(const LogMessage&) { } 560 | }; 561 | 562 | #define CHECK(cond) CRASH_UNLESS(cond) 563 | #define CHECK_LE(a, b) CRASH_UNLESS((a) <= (b)) 564 | #define CHECK_GE(a, b) CRASH_UNLESS((a) >= (b)) 565 | #define CHECK_EQ(a, b) CRASH_UNLESS((a) == (b)) 566 | #define CHECK_NE(a, b) CRASH_UNLESS((a) != (b)) 567 | #define CHECK_LT(a, b) CRASH_UNLESS((a) < (b)) 568 | #define CHECK_GT(a, b) CRASH_UNLESS((a) > (b)) 569 | #define CHECK_OK(cond) (cond).CheckSuccess() 570 | 571 | } // namespace snappy 572 | 573 | #endif // THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_TEST_H_ 574 | -------------------------------------------------------------------------------- /deps/snappy/snappy-1.1.7/snappy-stubs-internal.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. All Rights Reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of Google Inc. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | // 29 | // Various stubs for the open-source version of Snappy. 30 | 31 | #ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_INTERNAL_H_ 32 | #define THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_INTERNAL_H_ 33 | 34 | #ifdef HAVE_CONFIG_H 35 | #include "config.h" 36 | #endif 37 | 38 | #include 39 | 40 | #include 41 | #include 42 | #include 43 | 44 | #ifdef HAVE_SYS_MMAN_H 45 | #include 46 | #endif 47 | 48 | #ifdef HAVE_UNISTD_H 49 | #include 50 | #endif 51 | 52 | #if defined(_MSC_VER) 53 | #include 54 | #endif // defined(_MSC_VER) 55 | 56 | #include "snappy-stubs-public.h" 57 | 58 | #if defined(__x86_64__) 59 | 60 | // Enable 64-bit optimized versions of some routines. 61 | #define ARCH_K8 1 62 | 63 | #elif defined(__ppc64__) 64 | 65 | #define ARCH_PPC 1 66 | 67 | #elif defined(__aarch64__) 68 | 69 | #define ARCH_ARM 1 70 | 71 | #endif 72 | 73 | // Needed by OS X, among others. 74 | #ifndef MAP_ANONYMOUS 75 | #define MAP_ANONYMOUS MAP_ANON 76 | #endif 77 | 78 | // The size of an array, if known at compile-time. 79 | // Will give unexpected results if used on a pointer. 80 | // We undefine it first, since some compilers already have a definition. 81 | #ifdef ARRAYSIZE 82 | #undef ARRAYSIZE 83 | #endif 84 | #define ARRAYSIZE(a) (sizeof(a) / sizeof(*(a))) 85 | 86 | // Static prediction hints. 87 | #ifdef HAVE_BUILTIN_EXPECT 88 | #define SNAPPY_PREDICT_FALSE(x) (__builtin_expect(x, 0)) 89 | #define SNAPPY_PREDICT_TRUE(x) (__builtin_expect(!!(x), 1)) 90 | #else 91 | #define SNAPPY_PREDICT_FALSE(x) x 92 | #define SNAPPY_PREDICT_TRUE(x) x 93 | #endif 94 | 95 | // This is only used for recomputing the tag byte table used during 96 | // decompression; for simplicity we just remove it from the open-source 97 | // version (anyone who wants to regenerate it can just do the call 98 | // themselves within main()). 99 | #define DEFINE_bool(flag_name, default_value, description) \ 100 | bool FLAGS_ ## flag_name = default_value 101 | #define DECLARE_bool(flag_name) \ 102 | extern bool FLAGS_ ## flag_name 103 | 104 | namespace snappy { 105 | 106 | static const uint32 kuint32max = static_cast(0xFFFFFFFF); 107 | static const int64 kint64max = static_cast(0x7FFFFFFFFFFFFFFFLL); 108 | 109 | // Potentially unaligned loads and stores. 110 | 111 | // x86, PowerPC, and ARM64 can simply do these loads and stores native. 112 | 113 | #if defined(__i386__) || defined(__x86_64__) || defined(__powerpc__) || \ 114 | defined(__aarch64__) 115 | 116 | #define UNALIGNED_LOAD16(_p) (*reinterpret_cast(_p)) 117 | #define UNALIGNED_LOAD32(_p) (*reinterpret_cast(_p)) 118 | #define UNALIGNED_LOAD64(_p) (*reinterpret_cast(_p)) 119 | 120 | #define UNALIGNED_STORE16(_p, _val) (*reinterpret_cast(_p) = (_val)) 121 | #define UNALIGNED_STORE32(_p, _val) (*reinterpret_cast(_p) = (_val)) 122 | #define UNALIGNED_STORE64(_p, _val) (*reinterpret_cast(_p) = (_val)) 123 | 124 | // ARMv7 and newer support native unaligned accesses, but only of 16-bit 125 | // and 32-bit values (not 64-bit); older versions either raise a fatal signal, 126 | // do an unaligned read and rotate the words around a bit, or do the reads very 127 | // slowly (trip through kernel mode). There's no simple #define that says just 128 | // “ARMv7 or higher”, so we have to filter away all ARMv5 and ARMv6 129 | // sub-architectures. 130 | // 131 | // This is a mess, but there's not much we can do about it. 132 | // 133 | // To further complicate matters, only LDR instructions (single reads) are 134 | // allowed to be unaligned, not LDRD (two reads) or LDM (many reads). Unless we 135 | // explicitly tell the compiler that these accesses can be unaligned, it can and 136 | // will combine accesses. On armcc, the way to signal this is done by accessing 137 | // through the type (uint32 __packed *), but GCC has no such attribute 138 | // (it ignores __attribute__((packed)) on individual variables). However, 139 | // we can tell it that a _struct_ is unaligned, which has the same effect, 140 | // so we do that. 141 | 142 | #elif defined(__arm__) && \ 143 | !defined(__ARM_ARCH_4__) && \ 144 | !defined(__ARM_ARCH_4T__) && \ 145 | !defined(__ARM_ARCH_5__) && \ 146 | !defined(__ARM_ARCH_5T__) && \ 147 | !defined(__ARM_ARCH_5TE__) && \ 148 | !defined(__ARM_ARCH_5TEJ__) && \ 149 | !defined(__ARM_ARCH_6__) && \ 150 | !defined(__ARM_ARCH_6J__) && \ 151 | !defined(__ARM_ARCH_6K__) && \ 152 | !defined(__ARM_ARCH_6Z__) && \ 153 | !defined(__ARM_ARCH_6ZK__) && \ 154 | !defined(__ARM_ARCH_6T2__) 155 | 156 | #if __GNUC__ 157 | #define ATTRIBUTE_PACKED __attribute__((__packed__)) 158 | #else 159 | #define ATTRIBUTE_PACKED 160 | #endif 161 | 162 | namespace base { 163 | namespace internal { 164 | 165 | struct Unaligned16Struct { 166 | uint16 value; 167 | uint8 dummy; // To make the size non-power-of-two. 168 | } ATTRIBUTE_PACKED; 169 | 170 | struct Unaligned32Struct { 171 | uint32 value; 172 | uint8 dummy; // To make the size non-power-of-two. 173 | } ATTRIBUTE_PACKED; 174 | 175 | } // namespace internal 176 | } // namespace base 177 | 178 | #define UNALIGNED_LOAD16(_p) \ 179 | ((reinterpret_cast(_p))->value) 180 | #define UNALIGNED_LOAD32(_p) \ 181 | ((reinterpret_cast(_p))->value) 182 | 183 | #define UNALIGNED_STORE16(_p, _val) \ 184 | ((reinterpret_cast< ::snappy::base::internal::Unaligned16Struct *>(_p))->value = \ 185 | (_val)) 186 | #define UNALIGNED_STORE32(_p, _val) \ 187 | ((reinterpret_cast< ::snappy::base::internal::Unaligned32Struct *>(_p))->value = \ 188 | (_val)) 189 | 190 | // TODO(user): NEON supports unaligned 64-bit loads and stores. 191 | // See if that would be more efficient on platforms supporting it, 192 | // at least for copies. 193 | 194 | inline uint64 UNALIGNED_LOAD64(const void *p) { 195 | uint64 t; 196 | memcpy(&t, p, sizeof t); 197 | return t; 198 | } 199 | 200 | inline void UNALIGNED_STORE64(void *p, uint64 v) { 201 | memcpy(p, &v, sizeof v); 202 | } 203 | 204 | #else 205 | 206 | // These functions are provided for architectures that don't support 207 | // unaligned loads and stores. 208 | 209 | inline uint16 UNALIGNED_LOAD16(const void *p) { 210 | uint16 t; 211 | memcpy(&t, p, sizeof t); 212 | return t; 213 | } 214 | 215 | inline uint32 UNALIGNED_LOAD32(const void *p) { 216 | uint32 t; 217 | memcpy(&t, p, sizeof t); 218 | return t; 219 | } 220 | 221 | inline uint64 UNALIGNED_LOAD64(const void *p) { 222 | uint64 t; 223 | memcpy(&t, p, sizeof t); 224 | return t; 225 | } 226 | 227 | inline void UNALIGNED_STORE16(void *p, uint16 v) { 228 | memcpy(p, &v, sizeof v); 229 | } 230 | 231 | inline void UNALIGNED_STORE32(void *p, uint32 v) { 232 | memcpy(p, &v, sizeof v); 233 | } 234 | 235 | inline void UNALIGNED_STORE64(void *p, uint64 v) { 236 | memcpy(p, &v, sizeof v); 237 | } 238 | 239 | #endif 240 | 241 | // The following guarantees declaration of the byte swap functions. 242 | #if defined(SNAPPY_IS_BIG_ENDIAN) 243 | 244 | #ifdef HAVE_SYS_BYTEORDER_H 245 | #include 246 | #endif 247 | 248 | #ifdef HAVE_SYS_ENDIAN_H 249 | #include 250 | #endif 251 | 252 | #ifdef _MSC_VER 253 | #include 254 | #define bswap_16(x) _byteswap_ushort(x) 255 | #define bswap_32(x) _byteswap_ulong(x) 256 | #define bswap_64(x) _byteswap_uint64(x) 257 | 258 | #elif defined(__APPLE__) 259 | // Mac OS X / Darwin features 260 | #include 261 | #define bswap_16(x) OSSwapInt16(x) 262 | #define bswap_32(x) OSSwapInt32(x) 263 | #define bswap_64(x) OSSwapInt64(x) 264 | 265 | #elif defined(HAVE_BYTESWAP_H) 266 | #include 267 | 268 | #elif defined(bswap32) 269 | // FreeBSD defines bswap{16,32,64} in (already #included). 270 | #define bswap_16(x) bswap16(x) 271 | #define bswap_32(x) bswap32(x) 272 | #define bswap_64(x) bswap64(x) 273 | 274 | #elif defined(BSWAP_64) 275 | // Solaris 10 defines BSWAP_{16,32,64} in (already #included). 276 | #define bswap_16(x) BSWAP_16(x) 277 | #define bswap_32(x) BSWAP_32(x) 278 | #define bswap_64(x) BSWAP_64(x) 279 | 280 | #else 281 | 282 | inline uint16 bswap_16(uint16 x) { 283 | return (x << 8) | (x >> 8); 284 | } 285 | 286 | inline uint32 bswap_32(uint32 x) { 287 | x = ((x & 0xff00ff00UL) >> 8) | ((x & 0x00ff00ffUL) << 8); 288 | return (x >> 16) | (x << 16); 289 | } 290 | 291 | inline uint64 bswap_64(uint64 x) { 292 | x = ((x & 0xff00ff00ff00ff00ULL) >> 8) | ((x & 0x00ff00ff00ff00ffULL) << 8); 293 | x = ((x & 0xffff0000ffff0000ULL) >> 16) | ((x & 0x0000ffff0000ffffULL) << 16); 294 | return (x >> 32) | (x << 32); 295 | } 296 | 297 | #endif 298 | 299 | #endif // defined(SNAPPY_IS_BIG_ENDIAN) 300 | 301 | // Convert to little-endian storage, opposite of network format. 302 | // Convert x from host to little endian: x = LittleEndian.FromHost(x); 303 | // convert x from little endian to host: x = LittleEndian.ToHost(x); 304 | // 305 | // Store values into unaligned memory converting to little endian order: 306 | // LittleEndian.Store16(p, x); 307 | // 308 | // Load unaligned values stored in little endian converting to host order: 309 | // x = LittleEndian.Load16(p); 310 | class LittleEndian { 311 | public: 312 | // Conversion functions. 313 | #if defined(SNAPPY_IS_BIG_ENDIAN) 314 | 315 | static uint16 FromHost16(uint16 x) { return bswap_16(x); } 316 | static uint16 ToHost16(uint16 x) { return bswap_16(x); } 317 | 318 | static uint32 FromHost32(uint32 x) { return bswap_32(x); } 319 | static uint32 ToHost32(uint32 x) { return bswap_32(x); } 320 | 321 | static bool IsLittleEndian() { return false; } 322 | 323 | #else // !defined(SNAPPY_IS_BIG_ENDIAN) 324 | 325 | static uint16 FromHost16(uint16 x) { return x; } 326 | static uint16 ToHost16(uint16 x) { return x; } 327 | 328 | static uint32 FromHost32(uint32 x) { return x; } 329 | static uint32 ToHost32(uint32 x) { return x; } 330 | 331 | static bool IsLittleEndian() { return true; } 332 | 333 | #endif // !defined(SNAPPY_IS_BIG_ENDIAN) 334 | 335 | // Functions to do unaligned loads and stores in little-endian order. 336 | static uint16 Load16(const void *p) { 337 | return ToHost16(UNALIGNED_LOAD16(p)); 338 | } 339 | 340 | static void Store16(void *p, uint16 v) { 341 | UNALIGNED_STORE16(p, FromHost16(v)); 342 | } 343 | 344 | static uint32 Load32(const void *p) { 345 | return ToHost32(UNALIGNED_LOAD32(p)); 346 | } 347 | 348 | static void Store32(void *p, uint32 v) { 349 | UNALIGNED_STORE32(p, FromHost32(v)); 350 | } 351 | }; 352 | 353 | // Some bit-manipulation functions. 354 | class Bits { 355 | public: 356 | // Return floor(log2(n)) for positive integer n. Returns -1 iff n == 0. 357 | static int Log2Floor(uint32 n); 358 | 359 | // Return the first set least / most significant bit, 0-indexed. Returns an 360 | // undefined value if n == 0. FindLSBSetNonZero() is similar to ffs() except 361 | // that it's 0-indexed. 362 | static int FindLSBSetNonZero(uint32 n); 363 | 364 | #if defined(ARCH_K8) || defined(ARCH_PPC) || defined(ARCH_ARM) 365 | static int FindLSBSetNonZero64(uint64 n); 366 | #endif // defined(ARCH_K8) || defined(ARCH_PPC) || defined(ARCH_ARM) 367 | 368 | private: 369 | // No copying 370 | Bits(const Bits&); 371 | void operator=(const Bits&); 372 | }; 373 | 374 | #ifdef HAVE_BUILTIN_CTZ 375 | 376 | inline int Bits::Log2Floor(uint32 n) { 377 | return n == 0 ? -1 : 31 ^ __builtin_clz(n); 378 | } 379 | 380 | inline int Bits::FindLSBSetNonZero(uint32 n) { 381 | return __builtin_ctz(n); 382 | } 383 | 384 | #if defined(ARCH_K8) || defined(ARCH_PPC) || defined(ARCH_ARM) 385 | inline int Bits::FindLSBSetNonZero64(uint64 n) { 386 | return __builtin_ctzll(n); 387 | } 388 | #endif // defined(ARCH_K8) || defined(ARCH_PPC) || defined(ARCH_ARM) 389 | 390 | #elif defined(_MSC_VER) 391 | 392 | inline int Bits::Log2Floor(uint32 n) { 393 | unsigned long where; 394 | if (_BitScanReverse(&where, n)) { 395 | return where; 396 | } else { 397 | return -1; 398 | } 399 | } 400 | 401 | inline int Bits::FindLSBSetNonZero(uint32 n) { 402 | unsigned long where; 403 | if (_BitScanForward(&where, n)) return static_cast(where); 404 | return 32; 405 | } 406 | 407 | #if defined(ARCH_K8) || defined(ARCH_PPC) || defined(ARCH_ARM) 408 | inline int Bits::FindLSBSetNonZero64(uint64 n) { 409 | unsigned long where; 410 | if (_BitScanForward64(&where, n)) return static_cast(where); 411 | return 64; 412 | } 413 | #endif // defined(ARCH_K8) || defined(ARCH_PPC) || defined(ARCH_ARM) 414 | 415 | #else // Portable versions. 416 | 417 | inline int Bits::Log2Floor(uint32 n) { 418 | if (n == 0) 419 | return -1; 420 | int log = 0; 421 | uint32 value = n; 422 | for (int i = 4; i >= 0; --i) { 423 | int shift = (1 << i); 424 | uint32 x = value >> shift; 425 | if (x != 0) { 426 | value = x; 427 | log += shift; 428 | } 429 | } 430 | assert(value == 1); 431 | return log; 432 | } 433 | 434 | inline int Bits::FindLSBSetNonZero(uint32 n) { 435 | int rc = 31; 436 | for (int i = 4, shift = 1 << 4; i >= 0; --i) { 437 | const uint32 x = n << shift; 438 | if (x != 0) { 439 | n = x; 440 | rc -= shift; 441 | } 442 | shift >>= 1; 443 | } 444 | return rc; 445 | } 446 | 447 | #if defined(ARCH_K8) || defined(ARCH_PPC) || defined(ARCH_ARM) 448 | // FindLSBSetNonZero64() is defined in terms of FindLSBSetNonZero(). 449 | inline int Bits::FindLSBSetNonZero64(uint64 n) { 450 | const uint32 bottombits = static_cast(n); 451 | if (bottombits == 0) { 452 | // Bottom bits are zero, so scan in top bits 453 | return 32 + FindLSBSetNonZero(static_cast(n >> 32)); 454 | } else { 455 | return FindLSBSetNonZero(bottombits); 456 | } 457 | } 458 | #endif // defined(ARCH_K8) || defined(ARCH_PPC) || defined(ARCH_ARM) 459 | 460 | #endif // End portable versions. 461 | 462 | // Variable-length integer encoding. 463 | class Varint { 464 | public: 465 | // Maximum lengths of varint encoding of uint32. 466 | static const int kMax32 = 5; 467 | 468 | // Attempts to parse a varint32 from a prefix of the bytes in [ptr,limit-1]. 469 | // Never reads a character at or beyond limit. If a valid/terminated varint32 470 | // was found in the range, stores it in *OUTPUT and returns a pointer just 471 | // past the last byte of the varint32. Else returns NULL. On success, 472 | // "result <= limit". 473 | static const char* Parse32WithLimit(const char* ptr, const char* limit, 474 | uint32* OUTPUT); 475 | 476 | // REQUIRES "ptr" points to a buffer of length sufficient to hold "v". 477 | // EFFECTS Encodes "v" into "ptr" and returns a pointer to the 478 | // byte just past the last encoded byte. 479 | static char* Encode32(char* ptr, uint32 v); 480 | 481 | // EFFECTS Appends the varint representation of "value" to "*s". 482 | static void Append32(string* s, uint32 value); 483 | }; 484 | 485 | inline const char* Varint::Parse32WithLimit(const char* p, 486 | const char* l, 487 | uint32* OUTPUT) { 488 | const unsigned char* ptr = reinterpret_cast(p); 489 | const unsigned char* limit = reinterpret_cast(l); 490 | uint32 b, result; 491 | if (ptr >= limit) return NULL; 492 | b = *(ptr++); result = b & 127; if (b < 128) goto done; 493 | if (ptr >= limit) return NULL; 494 | b = *(ptr++); result |= (b & 127) << 7; if (b < 128) goto done; 495 | if (ptr >= limit) return NULL; 496 | b = *(ptr++); result |= (b & 127) << 14; if (b < 128) goto done; 497 | if (ptr >= limit) return NULL; 498 | b = *(ptr++); result |= (b & 127) << 21; if (b < 128) goto done; 499 | if (ptr >= limit) return NULL; 500 | b = *(ptr++); result |= (b & 127) << 28; if (b < 16) goto done; 501 | return NULL; // Value is too long to be a varint32 502 | done: 503 | *OUTPUT = result; 504 | return reinterpret_cast(ptr); 505 | } 506 | 507 | inline char* Varint::Encode32(char* sptr, uint32 v) { 508 | // Operate on characters as unsigneds 509 | unsigned char* ptr = reinterpret_cast(sptr); 510 | static const int B = 128; 511 | if (v < (1<<7)) { 512 | *(ptr++) = v; 513 | } else if (v < (1<<14)) { 514 | *(ptr++) = v | B; 515 | *(ptr++) = v>>7; 516 | } else if (v < (1<<21)) { 517 | *(ptr++) = v | B; 518 | *(ptr++) = (v>>7) | B; 519 | *(ptr++) = v>>14; 520 | } else if (v < (1<<28)) { 521 | *(ptr++) = v | B; 522 | *(ptr++) = (v>>7) | B; 523 | *(ptr++) = (v>>14) | B; 524 | *(ptr++) = v>>21; 525 | } else { 526 | *(ptr++) = v | B; 527 | *(ptr++) = (v>>7) | B; 528 | *(ptr++) = (v>>14) | B; 529 | *(ptr++) = (v>>21) | B; 530 | *(ptr++) = v>>28; 531 | } 532 | return reinterpret_cast(ptr); 533 | } 534 | 535 | // If you know the internal layout of the std::string in use, you can 536 | // replace this function with one that resizes the string without 537 | // filling the new space with zeros (if applicable) -- 538 | // it will be non-portable but faster. 539 | inline void STLStringResizeUninitialized(string* s, size_t new_size) { 540 | s->resize(new_size); 541 | } 542 | 543 | // Return a mutable char* pointing to a string's internal buffer, 544 | // which may not be null-terminated. Writing through this pointer will 545 | // modify the string. 546 | // 547 | // string_as_array(&str)[i] is valid for 0 <= i < str.size() until the 548 | // next call to a string method that invalidates iterators. 549 | // 550 | // As of 2006-04, there is no standard-blessed way of getting a 551 | // mutable reference to a string's internal buffer. However, issue 530 552 | // (http://www.open-std.org/JTC1/SC22/WG21/docs/lwg-defects.html#530) 553 | // proposes this as the method. It will officially be part of the standard 554 | // for C++0x. This should already work on all current implementations. 555 | inline char* string_as_array(string* str) { 556 | return str->empty() ? NULL : &*str->begin(); 557 | } 558 | 559 | } // namespace snappy 560 | 561 | #endif // THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_INTERNAL_H_ 562 | --------------------------------------------------------------------------------