├── .github
├── dependabot.yml
└── workflows
│ ├── release.yml
│ └── test.yml
├── .gitignore
├── .gitmodules
├── .npmignore
├── CHANGELOG.md
├── LICENSE
├── README.md
├── UPGRADING.md
├── binding.cc
├── binding.gyp
├── binding.js
├── chained-batch.js
├── deps
├── rocksdb
│ ├── build_version.cc
│ └── rocksdb.gyp
└── snappy
│ ├── freebsd
│ ├── config.h
│ └── snappy-stubs-public.h
│ ├── linux
│ ├── config.h
│ └── snappy-stubs-public.h
│ ├── mac
│ ├── config.h
│ └── snappy-stubs-public.h
│ ├── openbsd
│ ├── config.h
│ └── snappy-stubs-public.h
│ ├── snappy-1.1.7
│ ├── .appveyor.yml
│ ├── .travis.yml
│ ├── AUTHORS
│ ├── CMakeLists.txt
│ ├── CONTRIBUTING.md
│ ├── COPYING
│ ├── NEWS
│ ├── README.md
│ ├── cmake
│ │ ├── SnappyConfig.cmake
│ │ └── config.h.in
│ ├── format_description.txt
│ ├── framing_format.txt
│ ├── snappy-c.cc
│ ├── snappy-c.h
│ ├── snappy-internal.h
│ ├── snappy-sinksource.cc
│ ├── snappy-sinksource.h
│ ├── snappy-stubs-internal.cc
│ ├── snappy-stubs-internal.h
│ ├── snappy-stubs-public.h.in
│ ├── snappy-test.cc
│ ├── snappy-test.h
│ ├── snappy.cc
│ ├── snappy.h
│ ├── snappy_unittest.cc
│ └── testdata
│ │ ├── alice29.txt
│ │ ├── asyoulik.txt
│ │ ├── baddata1.snappy
│ │ ├── baddata2.snappy
│ │ ├── baddata3.snappy
│ │ ├── fireworks.jpeg
│ │ ├── geo.protodata
│ │ ├── html
│ │ ├── html_x_4
│ │ ├── kppkn.gtb
│ │ ├── lcet10.txt
│ │ ├── paper-100k.pdf
│ │ ├── plrabn12.txt
│ │ └── urls.10K
│ ├── snappy.gyp
│ ├── solaris
│ ├── config.h
│ └── snappy-stubs-public.h
│ └── win32
│ ├── config.h
│ └── snappy-stubs-public.h
├── iterator.js
├── leveldown.js
├── package.json
└── test
├── abstract-leveldown-test.js
├── approximate-size-test.js
├── chained-batch-gc-test.js
├── cleanup-hanging-iterators-test.js
├── clear-gc-test.js
├── common.js
├── compact-range-test.js
├── compression-test.js
├── destroy-test.js
├── electron.js
├── empty-range-option-test.js
├── env-cleanup-hook-test.js
├── env-cleanup-hook.js
├── gc.js
├── getproperty-test.js
├── iterator-gc-test.js
├── iterator-recursion-test.js
├── iterator-starvation-test.js
├── iterator-test.js
├── leak-tester-batch.js
├── leak-tester-iterator.js
├── leak-tester.js
├── leveldown-test.js
├── make.js
├── open-read-only-test.js
├── port-libuv-fix-test.js
├── repair-test.js
├── segfault-test.js
└── stack-blower.js
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | - package-ecosystem: npm
4 | directory: /
5 | schedule:
6 | interval: monthly
7 | ignore:
8 | - dependency-name: dependency-check
9 | - dependency-name: node-gyp
10 | - package-ecosystem: github-actions
11 | directory: /
12 | schedule:
13 | interval: monthly
14 |
--------------------------------------------------------------------------------
/.github/workflows/release.yml:
--------------------------------------------------------------------------------
1 | name: Release
2 | on:
3 | push:
4 | tags: ['*']
5 | jobs:
6 | build:
7 | permissions:
8 | contents: read
9 | strategy:
10 | matrix:
11 | include:
12 | - os: ubuntu-latest
13 | build-group: linux-x64
14 | # At the time of writing macos-latest is mac 10; we need 11 to build a universal binary.
15 | - os: macos-11
16 | build-group: darwin-x64+arm64
17 | - os: windows-latest
18 | build-group: win32-x64
19 | runs-on: ${{ matrix.os }}
20 | name: Build ${{ matrix.build-group }}
21 | env:
22 | BUILD_GROUP: ${{ matrix.build-group }}
23 | steps:
24 | - name: Checkout
25 | uses: actions/checkout@v3
26 | with:
27 | submodules: recursive
28 | - name: Set up node
29 | uses: actions/setup-node@v3
30 | with:
31 | node-version: 14
32 | architecture: x64
33 | - name: Install
34 | run: npm install --ignore-scripts
35 | - name: Prebuild
36 | run: npm run prebuild-$BUILD_GROUP
37 | shell: bash
38 | - name: Prepare artifact
39 | run: tar -zcvf $BUILD_GROUP.tar.gz -C prebuilds .
40 | shell: bash
41 | - name: Upload artifact
42 | uses: actions/upload-artifact@v3
43 | with:
44 | name: ${{ env.BUILD_GROUP }}
45 | path: ${{ env.BUILD_GROUP }}.tar.gz
46 | retention-days: 1
47 | release:
48 | needs: build
49 | permissions:
50 | contents: write
51 | runs-on: ubuntu-latest
52 | name: Release
53 | steps:
54 | - name: Checkout
55 | uses: actions/checkout@v3
56 | - name: Download artifacts
57 | uses: actions/download-artifact@v3
58 | with:
59 | path: artifacts
60 | - name: Create GitHub release
61 | uses: docker://antonyurchenko/git-release:v4
62 | env:
63 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
64 | with:
65 | args: artifacts/*/*.tar.gz
66 |
--------------------------------------------------------------------------------
/.github/workflows/test.yml:
--------------------------------------------------------------------------------
1 | name: Test
2 | on: [push, pull_request]
3 | permissions:
4 | contents: read
5 | jobs:
6 | test:
7 | strategy:
8 | matrix:
9 | # At the time of writing macos-latest is mac 10; we need 11 to build a universal binary.
10 | os: [ubuntu-latest, macos-11, windows-latest]
11 | node: [10, 12, 14]
12 | runs-on: ${{ matrix.os }}
13 | name: ${{ matrix.os }} / Node ${{ matrix.node }}
14 | steps:
15 | - name: Checkout
16 | uses: actions/checkout@v3
17 | with:
18 | submodules: recursive
19 | - name: Use node ${{ matrix.node }}
20 | uses: actions/setup-node@v3
21 | with:
22 | node-version: ${{ matrix.node }}
23 | architecture: x64
24 | - name: Install
25 | run: npm install
26 | - name: Test
27 | run: npm test
28 | - name: Coverage
29 | run: npm run coverage
30 | - name: Codecov
31 | uses: codecov/codecov-action@v3
32 | with:
33 | file: coverage/lcov.info
34 | - name: Test Electron
35 | if: ${{ matrix.node == '14' }}
36 | uses: GabrielBB/xvfb-action@v1
37 | with:
38 | run: npm run test-electron
39 | - name: Test GC
40 | run: npm run test-gc
41 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # When adding entries here, remember to also update `.npmignore`.
2 |
3 | node_modules/
4 | build/
5 | build-pre-gyp/
6 | Release/
7 | deps/*/Debug/
8 | libleveldb.so
9 | libleveldb.a
10 | leakydb
11 | *.sln
12 | *.vcxproj
13 | *.vcxproj.filters
14 | *.tlog
15 | *.obj
16 | *.1sdk.pdb
17 | *.lastbuildstate
18 | npm-debug.log
19 | prebuilds/
20 | yarn.lock
21 | package-lock.json
22 | .nyc_output/
23 | .benchmarks/
24 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "deps/rocksdb/rocksdb"]
2 | path = deps/rocksdb/rocksdb
3 | url = https://github.com/facebook/rocksdb.git
4 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | deps/**/*.md
2 | deps/**/.git
3 |
4 | deps/rocksdb/rocksdb/arcanist_util/
5 | deps/rocksdb/rocksdb/buckifier/
6 | deps/rocksdb/rocksdb/build_tools/
7 | deps/rocksdb/rocksdb/coverage/
8 | deps/rocksdb/rocksdb/docs/
9 | deps/rocksdb/rocksdb/examples/
10 | deps/rocksdb/rocksdb/fuzz/
11 | deps/rocksdb/rocksdb/hdfs/setup.sh
12 | deps/rocksdb/rocksdb/java/
13 | deps/rocksdb/rocksdb/third-party/gtest-*/
14 | deps/rocksdb/rocksdb/tools/advisor/
15 | deps/rocksdb/rocksdb/tools/rdb/
16 | deps/rocksdb/rocksdb/tools/dbench_monitor
17 | deps/rocksdb/rocksdb/tools/pflag
18 | deps/rocksdb/rocksdb/tools/*.sh
19 | deps/rocksdb/rocksdb/tools/*.py
20 | deps/rocksdb/rocksdb/tools/*.dmp
21 | deps/rocksdb/rocksdb/README.md
22 | deps/rocksdb/rocksdb/HISTORY.md
23 | deps/rocksdb/rocksdb/.circleci/
24 | deps/rocksdb/rocksdb/.github/
25 | deps/rocksdb/rocksdb/.lgtm.yml
26 | deps/rocksdb/rocksdb/defs.bzl
27 |
28 | deps/snappy/snappy*/testdata/
29 | deps/snappy/snappy*/*.txt
30 | deps/snappy/snappy*/README.md
31 |
32 | README
33 | INSTALL
34 | NEWS
35 | AUTHORS
36 | TODO
37 |
38 | # Build artifacts
39 | deps/*/Release/
40 | deps/*/Debug/
41 | *.tar.gz
42 | *.tgz
43 | build/
44 | build-pre-gyp/
45 | libleveldb.so
46 | libleveldb.a
47 | *.sln
48 | *.vcxproj
49 | *.vcxproj.filters
50 | .vscode
51 |
52 | # Benchmarks and tests
53 | bench/
54 | test/
55 | .benchmarks/
56 | *.csv
57 |
58 | # Misc
59 | .nyc_output/
60 | .github/
61 | yarn.lock
62 | .gitmodules
63 | .travis.yml
64 | appveyor.yml
65 | .appveyor.yml
66 | Dockerfile
67 | .dockerignore
68 | Vagrantfile
69 | .arcconfig
70 | .clang-format
71 | .watchmanconfig
72 |
73 | # Unknown
74 | leakydb
75 | test-data.tar
76 | test-data.db.tar
77 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright © 2012 Rod Vagg and the contributors to rocksdb.
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 all
13 | 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 THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # rocksdb
2 |
3 | **This package has been discontinued. Please see [Frequently Asked Questions](https://github.com/Level/community#faq).**
4 |
5 | ## Table of Contents
6 |
7 | Click to expand
8 |
9 | - [Introduction](#introduction)
10 | - [Supported Platforms](#supported-platforms)
11 | - [API](#api)
12 | - [Contributing](#contributing)
13 | - [Git Submodules](#git-submodules)
14 | - [Publishing](#publishing)
15 | - [Donate](#donate)
16 | - [License](#license)
17 |
18 |
19 |
20 | ## Introduction
21 |
22 | This module closely follows [`leveldown`](https://github.com/Level/leveldown) and implements the same API. The difference is that `leveldown` is a binding for [LevelDB](https://github.com/google/leveldb) while `rocksdb` is a binding for [RocksDB, Facebook's fork of LevelDB](https://github.com/facebook/rocksdb).
23 |
24 | It is **strongly recommended** that you use `levelup` in preference to `rocksdb` unless you have measurable performance reasons to do so. `levelup` is optimized for usability and safety. Although we are working to improve the safety of the `rocksdb` interface it is still easy to crash your Node process if you don't do things in just the right way.
25 |
26 | **If you are upgrading:** please see [UPGRADING.md](UPGRADING.md).
27 |
28 | ## Supported Platforms
29 |
30 | We aim to support _at least_ Active LTS and Current Node.js releases, Electron 5.0.0, as well as any future Node.js and Electron releases thanks to [N-API](https://nodejs.org/api/n-api.html). The minimum node version for `rocksdb` is `10.12.0`.
31 |
32 | The `rocksdb` npm package ships with prebuilt binaries for popular 64-bit platforms and is known to work on:
33 |
34 | - **Linux** (including ARM platforms such as Raspberry Pi and Kindle)
35 | - **Mac OS**
36 | - **Solaris** (SmartOS & Nodejitsu)
37 | - **FreeBSD**
38 | - **Windows**
39 |
40 | When installing `rocksdb`, [`node-gyp-build`](https://github.com/prebuild/node-gyp-build) will check if a compatible binary exists and fallback to a compile step if it doesn't. In that case you'll need a [valid `node-gyp` installation](https://github.com/nodejs/node-gyp#installation).
41 |
42 | If you don't want to use the prebuilt binary for the platform you are installing on, specify the `--build-from-source` flag when you install. If you are working on `rocksdb` itself and want to re-compile the C++ code it's enough to do `npm install`.
43 |
44 | ## API
45 |
46 | Please refer to [`leveldown`](https://github.com/Level/leveldown#api) for API documentation. The `db.open(options, callback)` method of `rocksdb` has a few additional options:
47 |
48 | - `readOnly` (boolean, default `false`): open database in read-only mode.
49 | - `infoLogLevel` (string, default `null`): verbosity of info log. One of `'debug'`, `'info'`, `'warn'`, `'error'`, `'fatal'`, `'header'` or `null` (disable).
50 |
51 | ## Contributing
52 |
53 | [`Level/rocksdb`](https://github.com/Level/rocksdb) is an **OPEN Open Source Project**. This means that:
54 |
55 | > Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project.
56 |
57 | See the [Contribution Guide](https://github.com/Level/community/blob/master/CONTRIBUTING.md) for more details.
58 |
59 | ### Git Submodules
60 |
61 | This project uses Git Submodules. This means that you should clone it recursively if you're planning on working on it:
62 |
63 | ```bash
64 | $ git clone --recurse-submodules https://github.com/Level/rocksdb.git
65 | ```
66 |
67 | Alternatively, you can initialize submodules after cloning:
68 |
69 | ```bash
70 | $ git submodule update --init --recursive
71 | ```
72 |
73 | ### Publishing
74 |
75 | 1. Increment the version: `npm version ..`
76 | 2. Push to GitHub: `git push --follow-tags`
77 | 3. Wait for CI to complete
78 | 4. Download prebuilds into `./prebuilds`: `npm run download-prebuilds`
79 | 5. Optionally verify loading a prebuild: `npm run test-prebuild`
80 | 6. Optionally verify which files npm will include: `canadian-pub`
81 | 7. Finally: `npm publish`
82 |
83 | ## Donate
84 |
85 | Support us with a monthly donation on [Open Collective](https://opencollective.com/level) and help us continue our work.
86 |
87 | ## License
88 |
89 | [MIT](LICENSE)
90 |
91 | _`rocksdb` builds on the excellent work of the LevelDB and Snappy teams from Google and additional contributors to the LevelDB fork by Facebook. LevelDB and Snappy are both issued under the [New BSD License](http://opensource.org/licenses/BSD-3-Clause). A large portion of `rocksdb` Windows support comes from the [Windows LevelDB port](http://code.google.com/r/kkowalczyk-leveldb/) (archived) by [Krzysztof Kowalczyk](http://blog.kowalczyk.info/) ([`@kjk`](https://twitter.com/kjk)). If you're using `rocksdb` on Windows, you should give him your thanks!_
92 |
93 | [level-badge]: https://leveljs.org/img/badge.svg
94 |
--------------------------------------------------------------------------------
/UPGRADING.md:
--------------------------------------------------------------------------------
1 | # Upgrade Guide
2 |
3 | This document describes breaking changes and how to upgrade. For a complete list of changes including minor and patch releases, please refer to the [changelog](CHANGELOG.md).
4 |
5 | ## 5.0.0
6 |
7 | Legacy range options have been removed ([Level/community#86](https://github.com/Level/community/issues/86)). If you previously did:
8 |
9 | ```js
10 | db.iterator({ start: 'a', end: 'z' })
11 | ```
12 |
13 | An error would now be thrown and you must instead do:
14 |
15 | ```js
16 | db.iterator({ gte: 'a', lte: 'z' })
17 | ```
18 |
19 | A db created or opened with this release cannot be opened by earlier versions, because RocksDB has been upgraded to 6.17.3 which effectively changes the default [`format_version`](https://rocksdb.org/blog/2019/03/08/format-version-4.html) from 2 to 4.
20 |
21 | This release also drops support of Node.js 8 ([Level/community#98](https://github.com/Level/community/issues/98)).
22 |
23 | ## 4.0.0
24 |
25 | **This is a rewrite to N-API and an upgrade to `abstract-leveldown` v6, which solves long-standing issues around serialization and type support.**
26 |
27 | ### N-API rewrite
28 |
29 | N-API is the latest interface for native addons in Node.js. Main benefit is that `rocksdb` became independent of the V8 version, which means it will be compatible with future versions of Node.js. As long as the native code doesn't change, it doesn't need to be recompiled as new versions of Node.js are released. This helps greatly with both maintenance and when delivering code to consumers.
30 |
31 | Because N-API has an experimental status in node 6 and early 8.x releases, support of node 6 has been dropped and the minimum node version for `rocksdb` is now 8.6.0. Conversely, for node >= 12, `rocksdb@4` is the minimum version.
32 |
33 | ### Prebuilt binaries are now shipped in npm package
34 |
35 | Previously, they were downloaded from GitHub by an npm `postinstall` script. Prebuilds for 32 bits Windows are no longer included.
36 |
37 | ### Info log is disabled by default
38 |
39 | RocksDB writes debug information to this log (a file on disk). Should you need this RocksDB feature, it can be enabled with a new `infoLogLevel` option. Please see [`README.md`](README.md) for details.
40 |
41 | ### Range options are now serialized
42 |
43 | Previously, range options like `lt` were passed through as-is by `abstract-leveldown`, unlike keys. For `rocksdb` it means that range option types other than a string or Buffer will be stringified.
44 |
45 | ### The rules for range options have been relaxed
46 |
47 | Because `null`, `undefined`, zero-length strings and zero-length buffers are significant types in encodings like `bytewise` and `charwise`, they became valid as range options in `abstract-leveldown`. This means `db.iterator({ gt: undefined })` is not the same as `db.iterator({})`.
48 |
49 | In the case of `rocksdb`, when used by itself, the aforementioned change means that `db.iterator({ gt: undefined })` is now effectively the same as `db.iterator({ gt: 'undefined' })`, making it explicit that `rocksdb` only supports strings and buffers.
50 |
51 | ### Seeking became part of official `abstract-leveldown` API
52 |
53 | As a result of this, the `target` argument in `iterator.seek(target)` is now serialized. Meaning any type other than a string or Buffer will be stringified. Like before, if the result is a zero-length string or Buffer, an error will be thrown.
54 |
55 | ### Nullish values are rejected
56 |
57 | In addition to rejecting `null` and `undefined` as _keys_, `abstract-leveldown` now also rejects these types as _values_, due to preexisting significance in streams and iterators.
58 |
59 | ### Zero-length array keys are rejected
60 |
61 | Though this was already the case, `abstract-leveldown` has replaced the behavior with an explicit `Array.isArray()` check and a new error message.
62 |
63 | ### The `sync` option of `chainedBatch` has moved
64 |
65 | The `sync` option has moved to `chainedBatch.write(options)`. Previously, `sync` was half-documented and half-implemented.
66 |
67 | ### Various segmentation faults have been fixed
68 |
69 | It is now safe to call `db.close()` before operations like `db.put()` complete, to call `db.iterator()` on a non-open db and to call `db.close()` having created many iterators regardless of their state (idle, nexting, ending or ended). To achieve this, `rocksdb` waits for pending operations before closing:
70 |
71 | ```js
72 | db.put('key', 'value', function (err) {
73 | console.log('this happens first')
74 | })
75 |
76 | db.close(function (err) {
77 | console.log('this happens second')
78 | })
79 | ```
80 |
81 | ## 3.0.0
82 |
83 | Dropped support for node 4. No other breaking changes.
84 |
85 | ## 2.0.0
86 |
87 | #### `.batch(array)` enforces objects
88 |
89 | This major release contains an upgrade to `abstract-leveldown` with a [breaking change](https://github.com/Level/abstract-leveldown/commit/a2621ad70571f6ade9d2be42632ece042e068805) for the array version of `.batch()`. This change ensures all elements in the batch array are objects.
90 |
91 | If you previously passed arrays to `.batch()` that contained `undefined` or `null`, they would be silently ignored. Now this will produce an error.
92 |
--------------------------------------------------------------------------------
/binding.gyp:
--------------------------------------------------------------------------------
1 | {
2 | "targets": [{
3 | "target_name": "leveldown"
4 | , "conditions": [
5 | ["OS == 'win'", {
6 | "defines": [
7 | "_HAS_EXCEPTIONS=1"
8 | , "OS_WIN=1"
9 | ]
10 | , "msvs_settings": {
11 | "VCCLCompilerTool": {
12 | "RuntimeTypeInfo": "false"
13 | , "EnableFunctionLevelLinking": "true"
14 | , "ExceptionHandling": "2"
15 | , "DisableSpecificWarnings": [ "4355", "4530" ,"4267", "4244", "4506" ]
16 | }
17 | , 'VCLinkerTool': {
18 | 'AdditionalDependencies': [
19 | # SDK import libs.
20 | 'Shlwapi.lib',
21 | 'rpcrt4.lib'
22 | ]
23 | }
24 | }
25 | }, { # OS != 'win'
26 | 'cflags!': [ '-fno-rtti' ]
27 | , 'cflags_cc!': [ '-fno-rtti' ]
28 | , 'cflags_cc+': [ '-frtti' ]
29 | }]
30 | , ["OS == 'mac'", {
31 | "cflags+": ["-fvisibility=hidden"],
32 | 'xcode_settings': {
33 | "GCC_SYMBOLS_PRIVATE_EXTERN": "YES" # -fvisibility=hidden
34 | , 'WARNING_CFLAGS': [
35 | '-Wno-sign-compare'
36 | , '-Wno-unused-variable'
37 | , '-Wno-unused-function'
38 | , '-Wno-ignored-qualifiers'
39 | ]
40 | , 'OTHER_CPLUSPLUSFLAGS': [
41 | '-mmacosx-version-min=10.8'
42 | , '-std=c++11'
43 | , '-stdlib=libc++'
44 | , '-arch x86_64'
45 | , '-arch arm64'
46 | ]
47 | , 'OTHER_LDFLAGS': [
48 | '-stdlib=libc++'
49 | , '-arch x86_64'
50 | , '-arch arm64'
51 | ]
52 | , 'GCC_ENABLE_CPP_RTTI': 'YES'
53 | , 'GCC_ENABLE_CPP_EXCEPTIONS': 'YES'
54 | , 'MACOSX_DEPLOYMENT_TARGET': '10.8'
55 | }
56 | }]
57 | , ['OS == "linux"', {
58 | 'cflags': []
59 | , 'cflags!': [ '-fno-tree-vrp', '-fno-exceptions' ]
60 | , 'cflags_cc!': [ '-fno-exceptions' ]
61 | }]
62 | ]
63 | , "dependencies": [
64 | "<(module_root_dir)/deps/rocksdb/rocksdb.gyp:rocksdb"
65 | ]
66 | , "include_dirs" : [
67 | " header file. */
14 | /* #undef HAVE_BYTESWAP_H */
15 |
16 | /* Define to 1 if you have the header file. */
17 | #define HAVE_DLFCN_H 1
18 |
19 | /* Use the gflags package for command-line parsing. */
20 | /* #undef HAVE_GFLAGS */
21 |
22 | /* Defined when Google Test is available. */
23 | /* #undef HAVE_GTEST */
24 |
25 | /* Define to 1 if you have the header file. */
26 | #define HAVE_INTTYPES_H 1
27 |
28 | /* Define to 1 if you have the `fastlz' library (-lfastlz). */
29 | /* #undef HAVE_LIBFASTLZ */
30 |
31 | /* Define to 1 if you have the `lzf' library (-llzf). */
32 | /* #undef HAVE_LIBLZF */
33 |
34 | /* Define to 1 if you have the `lzo2' library (-llzo2). */
35 | /* #undef HAVE_LIBLZO2 */
36 |
37 | /* Define to 1 if you have the `quicklz' library (-lquicklz). */
38 | /* #undef HAVE_LIBQUICKLZ */
39 |
40 | /* Define to 1 if you have the `z' library (-lz). */
41 | #define HAVE_LIBZ 1
42 |
43 | /* Define to 1 if you have the header file. */
44 | #define HAVE_MEMORY_H 1
45 |
46 | /* Define to 1 if you have the header file. */
47 | #define HAVE_STDDEF_H 1
48 |
49 | /* Define to 1 if you have the header file. */
50 | #define HAVE_STDINT_H 1
51 |
52 | /* Define to 1 if you have the header file. */
53 | #define HAVE_STDLIB_H 1
54 |
55 | /* Define to 1 if you have the header file. */
56 | #define HAVE_STRINGS_H 1
57 |
58 | /* Define to 1 if you have the header file. */
59 | #define HAVE_STRING_H 1
60 |
61 | /* Define to 1 if you have the header file. */
62 | /* #undef HAVE_SYS_BYTESWAP_H */
63 |
64 | /* Define to 1 if you have the header file. */
65 | #define HAVE_SYS_ENDIAN_H 1
66 |
67 | /* Define to 1 if you have the header file. */
68 | #define HAVE_SYS_MMAN_H 1
69 |
70 | /* Define to 1 if you have the header file. */
71 | #define HAVE_SYS_RESOURCE_H 1
72 |
73 | /* Define to 1 if you have the header file. */
74 | #define HAVE_SYS_STAT_H 1
75 |
76 | /* Define to 1 if you have the header file. */
77 | #define HAVE_SYS_TIME_H 1
78 |
79 | /* Define to 1 if you have the header file. */
80 | #define HAVE_SYS_TYPES_H 1
81 |
82 | /* Define to 1 if you have the header file. */
83 | #define HAVE_SYS_UIO_H 1
84 |
85 | /* Define to 1 if you have the header file. */
86 | #define HAVE_UNISTD_H 1
87 |
88 | /* Define to 1 if you have the header file. */
89 | /* #undef HAVE_WINDOWS_H */
90 |
91 | /* Define to the sub-directory in which libtool stores uninstalled libraries.
92 | */
93 | #define LT_OBJDIR ".libs/"
94 |
95 | /* Name of package */
96 | #define PACKAGE "snappy"
97 |
98 | /* Define to the address where bug reports for this package should be sent. */
99 | #define PACKAGE_BUGREPORT ""
100 |
101 | /* Define to the full name of this package. */
102 | #define PACKAGE_NAME "snappy"
103 |
104 | /* Define to the full name and version of this package. */
105 | #define PACKAGE_STRING "snappy 1.1.4"
106 |
107 | /* Define to the one symbol short name of this package. */
108 | #define PACKAGE_TARNAME "snappy"
109 |
110 | /* Define to the version of this package. */
111 | #define PACKAGE_VERSION "1.1.4"
112 |
113 | /* Define to 1 if you have the ANSI C header files. */
114 | #define STDC_HEADERS 1
115 |
116 | /* Version number of package */
117 | #define VERSION "1.1.4"
118 |
119 | /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
120 | significant byte first (like Motorola and SPARC, unlike Intel). */
121 | #if defined AC_APPLE_UNIVERSAL_BUILD
122 | # if defined __BIG_ENDIAN__
123 | # define WORDS_BIGENDIAN 1
124 | # endif
125 | #else
126 | # ifndef WORDS_BIGENDIAN
127 | /* # undef WORDS_BIGENDIAN */
128 | # endif
129 | #endif
130 |
131 | /* Define to `unsigned int' if does not define. */
132 | /* #undef size_t */
133 |
134 | /* Define to `int' if does not define. */
135 | /* #undef ssize_t */
136 |
--------------------------------------------------------------------------------
/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
40 | #include
41 | #endif
42 |
43 | #if 1
44 | #include
45 | #endif
46 |
47 | #if 1
48 | #include
49 | #endif
50 |
51 | #define SNAPPY_MAJOR 1
52 | #define SNAPPY_MINOR 1
53 | #define SNAPPY_PATCHLEVEL 4
54 | #define SNAPPY_VERSION \
55 | ((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL)
56 |
57 | #include
58 |
59 | namespace snappy {
60 |
61 | #if 1
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
80 |
81 | typedef std::string string;
82 |
83 | #ifndef DISALLOW_COPY_AND_ASSIGN
84 | #define DISALLOW_COPY_AND_ASSIGN(TypeName) \
85 | TypeName(const TypeName&); \
86 | void operator=(const TypeName&)
87 | #endif
88 |
89 | #if !1
90 | // Windows does not have an iovec type, yet the concept is universally useful.
91 | // It is simple to define it ourselves, so we put it inside our own namespace.
92 | struct iovec {
93 | void* iov_base;
94 | size_t iov_len;
95 | };
96 | #endif
97 |
98 | } // namespace snappy
99 |
100 | #endif // THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_
101 |
--------------------------------------------------------------------------------
/deps/snappy/linux/config.h:
--------------------------------------------------------------------------------
1 | /* config.h. Generated from config.h.in by configure. */
2 | /* config.h.in. Generated from configure.ac by autoheader. */
3 |
4 | /* Define if building universal (internal helper macro) */
5 | /* #undef AC_APPLE_UNIVERSAL_BUILD */
6 |
7 | /* Define to 1 if the compiler supports __builtin_ctz and friends. */
8 | #define HAVE_BUILTIN_CTZ 1
9 |
10 | /* Define to 1 if the compiler supports __builtin_expect. */
11 | #define HAVE_BUILTIN_EXPECT 1
12 |
13 | /* Define to 1 if you have the header file. */
14 | #define HAVE_BYTESWAP_H 1
15 |
16 | /* Define to 1 if you have the header file. */
17 | #define HAVE_DLFCN_H 1
18 |
19 | /* Use the gflags package for command-line parsing. */
20 | /* #undef HAVE_GFLAGS */
21 |
22 | /* Defined when Google Test is available. */
23 | /* #undef HAVE_GTEST */
24 |
25 | /* Define to 1 if you have the header file. */
26 | #define HAVE_INTTYPES_H 1
27 |
28 | /* Define to 1 if you have the `fastlz' library (-lfastlz). */
29 | /* #undef HAVE_LIBFASTLZ */
30 |
31 | /* Define to 1 if you have the `lzf' library (-llzf). */
32 | /* #undef HAVE_LIBLZF */
33 |
34 | /* Define to 1 if you have the `lzo2' library (-llzo2). */
35 | /* #undef HAVE_LIBLZO2 */
36 |
37 | /* Define to 1 if you have the `quicklz' library (-lquicklz). */
38 | /* #undef HAVE_LIBQUICKLZ */
39 |
40 | /* Define to 1 if you have the `z' library (-lz). */
41 | #define HAVE_LIBZ 1
42 |
43 | /* Define to 1 if you have the header file. */
44 | #define HAVE_MEMORY_H 1
45 |
46 | /* Define to 1 if you have the header file. */
47 | #define HAVE_STDDEF_H 1
48 |
49 | /* Define to 1 if you have the header file. */
50 | #define HAVE_STDINT_H 1
51 |
52 | /* Define to 1 if you have the header file. */
53 | #define HAVE_STDLIB_H 1
54 |
55 | /* Define to 1 if you have the header file. */
56 | #define HAVE_STRINGS_H 1
57 |
58 | /* Define to 1 if you have the header file. */
59 | #define HAVE_STRING_H 1
60 |
61 | /* Define to 1 if you have the header file. */
62 | /* #undef HAVE_SYS_BYTESWAP_H */
63 |
64 | /* Define to 1 if you have the header file. */
65 | /* #undef HAVE_SYS_ENDIAN_H */
66 |
67 | /* Define to 1 if you have the header file. */
68 | #define HAVE_SYS_MMAN_H 1
69 |
70 | /* Define to 1 if you have the header file. */
71 | #define HAVE_SYS_RESOURCE_H 1
72 |
73 | /* Define to 1 if you have the header file. */
74 | #define HAVE_SYS_STAT_H 1
75 |
76 | /* Define to 1 if you have the header file. */
77 | #define HAVE_SYS_TIME_H 1
78 |
79 | /* Define to 1 if you have the header file. */
80 | #define HAVE_SYS_TYPES_H 1
81 |
82 | /* Define to 1 if you have the header file. */
83 | #define HAVE_SYS_UIO_H 1
84 |
85 | /* Define to 1 if you have the header file. */
86 | #define HAVE_UNISTD_H 1
87 |
88 | /* Define to 1 if you have the header file. */
89 | /* #undef HAVE_WINDOWS_H */
90 |
91 | /* Define to the sub-directory in which libtool stores uninstalled libraries.
92 | */
93 | #define LT_OBJDIR ".libs/"
94 |
95 | /* Name of package */
96 | #define PACKAGE "snappy"
97 |
98 | /* Define to the address where bug reports for this package should be sent. */
99 | #define PACKAGE_BUGREPORT ""
100 |
101 | /* Define to the full name of this package. */
102 | #define PACKAGE_NAME "snappy"
103 |
104 | /* Define to the full name and version of this package. */
105 | #define PACKAGE_STRING "snappy 1.1.4"
106 |
107 | /* Define to the one symbol short name of this package. */
108 | #define PACKAGE_TARNAME "snappy"
109 |
110 | /* Define to the version of this package. */
111 | #define PACKAGE_VERSION "1.1.4"
112 |
113 | /* Define to 1 if you have the ANSI C header files. */
114 | #define STDC_HEADERS 1
115 |
116 | /* Version number of package */
117 | #define VERSION "1.1.4"
118 |
119 | /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
120 | significant byte first (like Motorola and SPARC, unlike Intel). */
121 | #if defined AC_APPLE_UNIVERSAL_BUILD
122 | # if defined __BIG_ENDIAN__
123 | # define WORDS_BIGENDIAN 1
124 | # endif
125 | #else
126 | # ifndef WORDS_BIGENDIAN
127 | /* # undef WORDS_BIGENDIAN */
128 | # endif
129 | #endif
130 |
131 | /* Define to `unsigned int' if does not define. */
132 | /* #undef size_t */
133 |
134 | /* Define to `int' if does not define. */
135 | /* #undef ssize_t */
136 |
--------------------------------------------------------------------------------
/deps/snappy/linux/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
40 | #include
41 | #endif
42 |
43 | #if 1
44 | #include
45 | #endif
46 |
47 | #if 1
48 | #include
49 | #endif
50 |
51 | #define SNAPPY_MAJOR 1
52 | #define SNAPPY_MINOR 1
53 | #define SNAPPY_PATCHLEVEL 4
54 | #define SNAPPY_VERSION \
55 | ((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL)
56 |
57 | #include
58 |
59 | namespace snappy {
60 |
61 | #if 1
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
80 |
81 | typedef std::string string;
82 |
83 | #ifndef DISALLOW_COPY_AND_ASSIGN
84 | #define DISALLOW_COPY_AND_ASSIGN(TypeName) \
85 | TypeName(const TypeName&); \
86 | void operator=(const TypeName&)
87 | #endif
88 |
89 | #if !1
90 | // Windows does not have an iovec type, yet the concept is universally useful.
91 | // It is simple to define it ourselves, so we put it inside our own namespace.
92 | struct iovec {
93 | void* iov_base;
94 | size_t iov_len;
95 | };
96 | #endif
97 |
98 | } // namespace snappy
99 |
100 | #endif // THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_
101 |
--------------------------------------------------------------------------------
/deps/snappy/mac/config.h:
--------------------------------------------------------------------------------
1 | /* config.h. Generated from config.h.in by configure. */
2 | /* config.h.in. Generated from configure.ac by autoheader. */
3 |
4 | /* Define if building universal (internal helper macro) */
5 | /* #undef AC_APPLE_UNIVERSAL_BUILD */
6 |
7 | /* Define to 1 if the compiler supports __builtin_ctz and friends. */
8 | #define HAVE_BUILTIN_CTZ 1
9 |
10 | /* Define to 1 if the compiler supports __builtin_expect. */
11 | #define HAVE_BUILTIN_EXPECT 1
12 |
13 | /* Define to 1 if you have the header file. */
14 | /* #undef HAVE_BYTESWAP_H */
15 |
16 | /* Define to 1 if you have the header file. */
17 | #define HAVE_DLFCN_H 1
18 |
19 | /* Use the gflags package for command-line parsing. */
20 | /* #undef HAVE_GFLAGS */
21 |
22 | /* Defined when Google Test is available. */
23 | /* #undef HAVE_GTEST */
24 |
25 | /* Define to 1 if you have the header file. */
26 | #define HAVE_INTTYPES_H 1
27 |
28 | /* Define to 1 if you have the `fastlz' library (-lfastlz). */
29 | /* #undef HAVE_LIBFASTLZ */
30 |
31 | /* Define to 1 if you have the `lzf' library (-llzf). */
32 | /* #undef HAVE_LIBLZF */
33 |
34 | /* Define to 1 if you have the `lzo2' library (-llzo2). */
35 | /* #undef HAVE_LIBLZO2 */
36 |
37 | /* Define to 1 if you have the `quicklz' library (-lquicklz). */
38 | /* #undef HAVE_LIBQUICKLZ */
39 |
40 | /* Define to 1 if you have the `z' library (-lz). */
41 | #define HAVE_LIBZ 1
42 |
43 | /* Define to 1 if you have the header file. */
44 | #define HAVE_MEMORY_H 1
45 |
46 | /* Define to 1 if you have the header file. */
47 | #define HAVE_STDDEF_H 1
48 |
49 | /* Define to 1 if you have the header file. */
50 | #define HAVE_STDINT_H 1
51 |
52 | /* Define to 1 if you have the header file. */
53 | #define HAVE_STDLIB_H 1
54 |
55 | /* Define to 1 if you have the header file. */
56 | #define HAVE_STRINGS_H 1
57 |
58 | /* Define to 1 if you have the header file. */
59 | #define HAVE_STRING_H 1
60 |
61 | /* Define to 1 if you have the header file. */
62 | /* #undef HAVE_SYS_BYTESWAP_H */
63 |
64 | /* Define to 1 if you have the header file. */
65 | /* #undef HAVE_SYS_ENDIAN_H */
66 |
67 | /* Define to 1 if you have the header file. */
68 | #define HAVE_SYS_MMAN_H 1
69 |
70 | /* Define to 1 if you have the header file. */
71 | #define HAVE_SYS_RESOURCE_H 1
72 |
73 | /* Define to 1 if you have the header file. */
74 | #define HAVE_SYS_STAT_H 1
75 |
76 | /* Define to 1 if you have the header file. */
77 | #define HAVE_SYS_TIME_H 1
78 |
79 | /* Define to 1 if you have the header file. */
80 | #define HAVE_SYS_TYPES_H 1
81 |
82 | /* Define to 1 if you have the header file. */
83 | #define HAVE_SYS_UIO_H 1
84 |
85 | /* Define to 1 if you have the header file. */
86 | #define HAVE_UNISTD_H 1
87 |
88 | /* Define to 1 if you have the header file. */
89 | /* #undef HAVE_WINDOWS_H */
90 |
91 | /* Define to the sub-directory where libtool stores uninstalled libraries. */
92 | #define LT_OBJDIR ".libs/"
93 |
94 | /* Name of package */
95 | #define PACKAGE "snappy"
96 |
97 | /* Define to the address where bug reports for this package should be sent. */
98 | #define PACKAGE_BUGREPORT ""
99 |
100 | /* Define to the full name of this package. */
101 | #define PACKAGE_NAME "snappy"
102 |
103 | /* Define to the full name and version of this package. */
104 | #define PACKAGE_STRING "snappy 1.1.4"
105 |
106 | /* Define to the one symbol short name of this package. */
107 | #define PACKAGE_TARNAME "snappy"
108 |
109 | /* Define to the home page for this package. */
110 | #define PACKAGE_URL ""
111 |
112 | /* Define to the version of this package. */
113 | #define PACKAGE_VERSION "1.1.4"
114 |
115 | /* Define to 1 if you have the ANSI C header files. */
116 | #define STDC_HEADERS 1
117 |
118 | /* Version number of package */
119 | #define VERSION "1.1.4"
120 |
121 | /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
122 | significant byte first (like Motorola and SPARC, unlike Intel). */
123 | #if defined AC_APPLE_UNIVERSAL_BUILD
124 | # if defined __BIG_ENDIAN__
125 | # define WORDS_BIGENDIAN 1
126 | # endif
127 | #else
128 | # ifndef WORDS_BIGENDIAN
129 | /* # undef WORDS_BIGENDIAN */
130 | # endif
131 | #endif
132 |
133 | /* Define to `unsigned int' if does not define. */
134 | /* #undef size_t */
135 |
136 | /* Define to `int' if does not define. */
137 | /* #undef ssize_t */
138 |
--------------------------------------------------------------------------------
/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
40 | #include
41 | #endif
42 |
43 | #if 1
44 | #include
45 | #endif
46 |
47 | #if 1
48 | #include
49 | #endif
50 |
51 | #define SNAPPY_MAJOR 1
52 | #define SNAPPY_MINOR 1
53 | #define SNAPPY_PATCHLEVEL 4
54 | #define SNAPPY_VERSION \
55 | ((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL)
56 |
57 | #include
58 |
59 | namespace snappy {
60 |
61 | #if 1
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
80 |
81 | typedef std::string string;
82 |
83 | #ifndef DISALLOW_COPY_AND_ASSIGN
84 | #define DISALLOW_COPY_AND_ASSIGN(TypeName) \
85 | TypeName(const TypeName&); \
86 | void operator=(const TypeName&)
87 | #endif
88 |
89 | #if !1
90 | // Windows does not have an iovec type, yet the concept is universally useful.
91 | // It is simple to define it ourselves, so we put it inside our own namespace.
92 | struct iovec {
93 | void* iov_base;
94 | size_t iov_len;
95 | };
96 | #endif
97 |
98 | } // namespace snappy
99 |
100 | #endif // THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_
101 |
--------------------------------------------------------------------------------
/deps/snappy/openbsd/config.h:
--------------------------------------------------------------------------------
1 | /* config.h. Generated from config.h.in by configure. */
2 | /* config.h.in. Generated from configure.ac by autoheader. */
3 |
4 | /* Define if building universal (internal helper macro) */
5 | /* #undef AC_APPLE_UNIVERSAL_BUILD */
6 |
7 | /* Define to 1 if the compiler supports __builtin_ctz and friends. */
8 | #define HAVE_BUILTIN_CTZ 1
9 |
10 | /* Define to 1 if the compiler supports __builtin_expect. */
11 | #define HAVE_BUILTIN_EXPECT 1
12 |
13 | /* Define to 1 if you have the header file. */
14 | /* #undef HAVE_BYTESWAP_H */
15 |
16 | /* Define to 1 if you have the header file. */
17 | #define HAVE_DLFCN_H 1
18 |
19 | /* Use the gflags package for command-line parsing. */
20 | /* #undef HAVE_GFLAGS */
21 |
22 | /* Defined when Google Test is available. */
23 | /* #undef HAVE_GTEST */
24 |
25 | /* Define to 1 if you have the header file. */
26 | #define HAVE_INTTYPES_H 1
27 |
28 | /* Define to 1 if you have the `fastlz' library (-lfastlz). */
29 | /* #undef HAVE_LIBFASTLZ */
30 |
31 | /* Define to 1 if you have the `lzf' library (-llzf). */
32 | /* #undef HAVE_LIBLZF */
33 |
34 | /* Define to 1 if you have the `lzo2' library (-llzo2). */
35 | /* #undef HAVE_LIBLZO2 */
36 |
37 | /* Define to 1 if you have the `quicklz' library (-lquicklz). */
38 | /* #undef HAVE_LIBQUICKLZ */
39 |
40 | /* Define to 1 if you have the `z' library (-lz). */
41 | #define HAVE_LIBZ 1
42 |
43 | /* Define to 1 if you have the header file. */
44 | #define HAVE_MEMORY_H 1
45 |
46 | /* Define to 1 if you have the header file. */
47 | #define HAVE_STDDEF_H 1
48 |
49 | /* Define to 1 if you have the header file. */
50 | #define HAVE_STDINT_H 1
51 |
52 | /* Define to 1 if you have the header file. */
53 | #define HAVE_STDLIB_H 1
54 |
55 | /* Define to 1 if you have the header file. */
56 | #define HAVE_STRINGS_H 1
57 |
58 | /* Define to 1 if you have the header file. */
59 | #define HAVE_STRING_H 1
60 |
61 | /* Define to 1 if you have the header file. */
62 | /* #undef HAVE_SYS_BYTESWAP_H */
63 |
64 | /* Define to 1 if you have the header file. */
65 | #define HAVE_SYS_ENDIAN_H 1
66 |
67 | /* Define to 1 if you have the header file. */
68 | #define HAVE_SYS_MMAN_H 1
69 |
70 | /* Define to 1 if you have the header file. */
71 | #define HAVE_SYS_RESOURCE_H 1
72 |
73 | /* Define to 1 if you have the header file. */
74 | #define HAVE_SYS_STAT_H 1
75 |
76 | /* Define to 1 if you have the header file. */
77 | #define HAVE_SYS_TIME_H 1
78 |
79 | /* Define to 1 if you have the header file. */
80 | #define HAVE_SYS_TYPES_H 1
81 |
82 | /* Define to 1 if you have the header file. */
83 | #define HAVE_SYS_UIO_H 1
84 |
85 | /* Define to 1 if you have the header file. */
86 | #define HAVE_UNISTD_H 1
87 |
88 | /* Define to 1 if you have the header file. */
89 | /* #undef HAVE_WINDOWS_H */
90 |
91 | /* Define to the sub-directory in which libtool stores uninstalled libraries.
92 | */
93 | #define LT_OBJDIR ".libs/"
94 |
95 | /* Name of package */
96 | #define PACKAGE "snappy"
97 |
98 | /* Define to the address where bug reports for this package should be sent. */
99 | #define PACKAGE_BUGREPORT ""
100 |
101 | /* Define to the full name of this package. */
102 | #define PACKAGE_NAME "snappy"
103 |
104 | /* Define to the full name and version of this package. */
105 | #define PACKAGE_STRING "snappy 1.1.4"
106 |
107 | /* Define to the one symbol short name of this package. */
108 | #define PACKAGE_TARNAME "snappy"
109 |
110 | /* Define to the version of this package. */
111 | #define PACKAGE_VERSION "1.1.4"
112 |
113 | /* Define to 1 if you have the ANSI C header files. */
114 | #define STDC_HEADERS 1
115 |
116 | /* Version number of package */
117 | #define VERSION "1.1.4"
118 |
119 | /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
120 | significant byte first (like Motorola and SPARC, unlike Intel). */
121 | #if defined AC_APPLE_UNIVERSAL_BUILD
122 | # if defined __BIG_ENDIAN__
123 | # define WORDS_BIGENDIAN 1
124 | # endif
125 | #else
126 | # ifndef WORDS_BIGENDIAN
127 | /* # undef WORDS_BIGENDIAN */
128 | # endif
129 | #endif
130 |
131 | /* Define to `unsigned int' if does not define. */
132 | /* #undef size_t */
133 |
134 | /* Define to `int' if does not define. */
135 | /* #undef ssize_t */
136 |
--------------------------------------------------------------------------------
/deps/snappy/openbsd/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
40 | #include
41 | #endif
42 |
43 | #if 1
44 | #include
45 | #endif
46 |
47 | #if 1
48 | #include
49 | #endif
50 |
51 | #define SNAPPY_MAJOR 1
52 | #define SNAPPY_MINOR 1
53 | #define SNAPPY_PATCHLEVEL 4
54 | #define SNAPPY_VERSION \
55 | ((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL)
56 |
57 | #include
58 |
59 | namespace snappy {
60 |
61 | #if 1
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
80 |
81 | typedef std::string string;
82 |
83 | #ifndef DISALLOW_COPY_AND_ASSIGN
84 | #define DISALLOW_COPY_AND_ASSIGN(TypeName) \
85 | TypeName(const TypeName&); \
86 | void operator=(const TypeName&)
87 | #endif
88 |
89 | #if !1
90 | // Windows does not have an iovec type, yet the concept is universally useful.
91 | // It is simple to define it ourselves, so we put it inside our own namespace.
92 | struct iovec {
93 | void* iov_base;
94 | size_t iov_len;
95 | };
96 | #endif
97 |
98 | } // namespace snappy
99 |
100 | #endif // THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_
101 |
--------------------------------------------------------------------------------
/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-1.1.7/AUTHORS:
--------------------------------------------------------------------------------
1 | opensource@google.com
2 |
--------------------------------------------------------------------------------
/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/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 |
--------------------------------------------------------------------------------
/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/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 |
--------------------------------------------------------------------------------
/deps/snappy/snappy-1.1.7/cmake/SnappyConfig.cmake:
--------------------------------------------------------------------------------
1 | include("${CMAKE_CURRENT_LIST_DIR}/SnappyTargets.cmake")
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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.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 |
--------------------------------------------------------------------------------
/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/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-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-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 |
--------------------------------------------------------------------------------
/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/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.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/testdata/baddata1.snappy:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Level/rocksdb/6ed1ccbdf4937521d5e75bc1bb785f8323d73651/deps/snappy/snappy-1.1.7/testdata/baddata1.snappy
--------------------------------------------------------------------------------
/deps/snappy/snappy-1.1.7/testdata/baddata2.snappy:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Level/rocksdb/6ed1ccbdf4937521d5e75bc1bb785f8323d73651/deps/snappy/snappy-1.1.7/testdata/baddata2.snappy
--------------------------------------------------------------------------------
/deps/snappy/snappy-1.1.7/testdata/baddata3.snappy:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Level/rocksdb/6ed1ccbdf4937521d5e75bc1bb785f8323d73651/deps/snappy/snappy-1.1.7/testdata/baddata3.snappy
--------------------------------------------------------------------------------
/deps/snappy/snappy-1.1.7/testdata/fireworks.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Level/rocksdb/6ed1ccbdf4937521d5e75bc1bb785f8323d73651/deps/snappy/snappy-1.1.7/testdata/fireworks.jpeg
--------------------------------------------------------------------------------
/deps/snappy/snappy-1.1.7/testdata/geo.protodata:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Level/rocksdb/6ed1ccbdf4937521d5e75bc1bb785f8323d73651/deps/snappy/snappy-1.1.7/testdata/geo.protodata
--------------------------------------------------------------------------------
/deps/snappy/snappy-1.1.7/testdata/paper-100k.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Level/rocksdb/6ed1ccbdf4937521d5e75bc1bb785f8323d73651/deps/snappy/snappy-1.1.7/testdata/paper-100k.pdf
--------------------------------------------------------------------------------
/deps/snappy/snappy.gyp:
--------------------------------------------------------------------------------
1 | {'targets': [{
2 | 'variables': {
3 | 'conditions': [
4 | ['OS=="linux"', {'os_include': 'linux'}]
5 | , ['OS=="mac"', {'os_include': 'mac'}]
6 | , ['OS=="solaris"', {'os_include': 'solaris'}]
7 | , ['OS=="win"', {'os_include': 'win32'}]
8 | , ['OS=="freebsd"', {'os_include': 'freebsd'}]
9 | , ['OS=="openbsd"', {'os_include': 'openbsd'}]
10 | ]
11 | }
12 | , 'target_name': 'snappy'
13 | , 'type': 'static_library'
14 | # Overcomes an issue with the linker and thin .a files on SmartOS
15 | , 'standalone_static_library': 1
16 | , 'include_dirs': [
17 | '<(os_include)'
18 | , 'snappy-1.1.7'
19 | ]
20 | , 'direct_dependent_settings': {
21 | 'include_dirs': [
22 | '<(os_include)'
23 | , 'snappy-1.1.7'
24 | ]
25 | }
26 | , 'defines': [
27 | 'HAVE_CONFIG_H=1'
28 | ]
29 | , 'conditions': [
30 | ['OS == "win"', {
31 | 'defines': [
32 | '_HAS_EXCEPTIONS=0'
33 | ]
34 | , 'msvs_settings': {
35 | 'VCCLCompilerTool': {
36 | 'RuntimeTypeInfo': 'false'
37 | , 'EnableFunctionLevelLinking': 'true'
38 | , 'ExceptionHandling': '2'
39 | , 'DisableSpecificWarnings': [ '4355', '4530' ,'4267', '4244', '4506', '4018' ]
40 | }
41 | }
42 | }]
43 | , ['OS == "linux"', {
44 | 'cflags': [
45 | '-Wno-sign-compare'
46 | , '-Wno-unused-function'
47 | ]
48 | , 'cflags!': [ '-fno-tree-vrp' ]
49 | }]
50 | , ['OS == "freebsd"', {
51 | 'cflags': [
52 | '-Wno-sign-compare'
53 | , '-Wno-unused-function'
54 | ]
55 | }]
56 | , ['OS == "openbsd"', {
57 | 'cflags': [
58 | '-Wno-sign-compare'
59 | , '-Wno-unused-function'
60 | ]
61 | }]
62 | , ['OS == "solaris"', {
63 | 'cflags': [
64 | '-Wno-sign-compare'
65 | , '-Wno-unused-function'
66 | ]
67 | }]
68 | , ['OS == "mac"', {
69 | 'xcode_settings': {
70 | 'WARNING_CFLAGS': [
71 | '-Wno-sign-compare'
72 | , '-Wno-unused-function'
73 | ]
74 | , 'OTHER_CFLAGS': [
75 | '-arch x86_64'
76 | , '-arch arm64'
77 | ]
78 | }
79 | }]
80 | ]
81 | , 'sources': [
82 | 'snappy-1.1.7/snappy-internal.h'
83 | , 'snappy-1.1.7/snappy-sinksource.cc'
84 | , 'snappy-1.1.7/snappy-sinksource.h'
85 | , 'snappy-1.1.7/snappy-stubs-internal.cc'
86 | , 'snappy-1.1.7/snappy-stubs-internal.h'
87 | , 'snappy-1.1.7/snappy.cc'
88 | , 'snappy-1.1.7/snappy.h'
89 | ]
90 | }]}
91 |
--------------------------------------------------------------------------------
/deps/snappy/solaris/config.h:
--------------------------------------------------------------------------------
1 | /* config.h. Generated from config.h.in by configure. */
2 | /* config.h.in. Generated from configure.ac by autoheader. */
3 |
4 | /* Define if building universal (internal helper macro) */
5 | /* #undef AC_APPLE_UNIVERSAL_BUILD */
6 |
7 | /* Define to 1 if the compiler supports __builtin_ctz and friends. */
8 | #define HAVE_BUILTIN_CTZ 1
9 |
10 | /* Define to 1 if the compiler supports __builtin_expect. */
11 | #define HAVE_BUILTIN_EXPECT 1
12 |
13 | /* Define to 1 if you have the header file. */
14 | /* #undef HAVE_BYTESWAP_H */
15 |
16 | /* Define to 1 if you have the header file. */
17 | #define HAVE_DLFCN_H 1
18 |
19 | /* Use the gflags package for command-line parsing. */
20 | /* #undef HAVE_GFLAGS */
21 |
22 | /* Defined when Google Test is available. */
23 | /* #undef HAVE_GTEST */
24 |
25 | /* Define to 1 if you have the header file. */
26 | #define HAVE_INTTYPES_H 1
27 |
28 | /* Define to 1 if you have the `fastlz' library (-lfastlz). */
29 | /* #undef HAVE_LIBFASTLZ */
30 |
31 | /* Define to 1 if you have the `lzf' library (-llzf). */
32 | /* #undef HAVE_LIBLZF */
33 |
34 | /* Define to 1 if you have the `lzo2' library (-llzo2). */
35 | #define HAVE_LIBLZO2 1
36 |
37 | /* Define to 1 if you have the `quicklz' library (-lquicklz). */
38 | /* #undef HAVE_LIBQUICKLZ */
39 |
40 | /* Define to 1 if you have the `z' library (-lz). */
41 | #define HAVE_LIBZ 1
42 |
43 | /* Define to 1 if you have the header file. */
44 | #define HAVE_MEMORY_H 1
45 |
46 | /* Define to 1 if you have the header file. */
47 | #define HAVE_STDDEF_H 1
48 |
49 | /* Define to 1 if you have the header file. */
50 | #define HAVE_STDINT_H 1
51 |
52 | /* Define to 1 if you have the header file. */
53 | #define HAVE_STDLIB_H 1
54 |
55 | /* Define to 1 if you have the header file. */
56 | #define HAVE_STRINGS_H 1
57 |
58 | /* Define to 1 if you have the header file. */
59 | #define HAVE_STRING_H 1
60 |
61 | /* Define to 1 if you have the header file. */
62 | /* #undef HAVE_SYS_BYTESWAP_H */
63 |
64 | /* Define to 1 if you have the header file. */
65 | /* #undef HAVE_SYS_ENDIAN_H */
66 |
67 | /* Define to 1 if you have the header file. */
68 | #define HAVE_SYS_MMAN_H 1
69 |
70 | /* Define to 1 if you have the header file. */
71 | #define HAVE_SYS_RESOURCE_H 1
72 |
73 | /* Define to 1 if you have the header file. */
74 | #define HAVE_SYS_STAT_H 1
75 |
76 | /* Define to 1 if you have the header file. */
77 | #define HAVE_SYS_TIME_H 1
78 |
79 | /* Define to 1 if you have the header file. */
80 | #define HAVE_SYS_TYPES_H 1
81 |
82 | /* Define to 1 if you have the header file. */
83 | #define HAVE_SYS_UIO_H 1
84 |
85 | /* Define to 1 if you have the header file. */
86 | #define HAVE_UNISTD_H 1
87 |
88 | /* Define to 1 if you have the header file. */
89 | /* #undef HAVE_WINDOWS_H */
90 |
91 | /* Define to the sub-directory in which libtool stores uninstalled libraries.
92 | */
93 | #define LT_OBJDIR ".libs/"
94 |
95 | /* Name of package */
96 | #define PACKAGE "snappy"
97 |
98 | /* Define to the address where bug reports for this package should be sent. */
99 | #define PACKAGE_BUGREPORT ""
100 |
101 | /* Define to the full name of this package. */
102 | #define PACKAGE_NAME "snappy"
103 |
104 | /* Define to the full name and version of this package. */
105 | #define PACKAGE_STRING "snappy 1.1.4"
106 |
107 | /* Define to the one symbol short name of this package. */
108 | #define PACKAGE_TARNAME "snappy"
109 |
110 | /* Define to the version of this package. */
111 | #define PACKAGE_VERSION "1.1.4"
112 |
113 | /* Define to 1 if you have the ANSI C header files. */
114 | #define STDC_HEADERS 1
115 |
116 | /* Version number of package */
117 | #define VERSION "1.1.4"
118 |
119 | /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
120 | significant byte first (like Motorola and SPARC, unlike Intel). */
121 | #if defined AC_APPLE_UNIVERSAL_BUILD
122 | # if defined __BIG_ENDIAN__
123 | # define WORDS_BIGENDIAN 1
124 | # endif
125 | #else
126 | # ifndef WORDS_BIGENDIAN
127 | /* # undef WORDS_BIGENDIAN */
128 | # endif
129 | #endif
130 |
131 | /* Define to `unsigned int' if does not define. */
132 | /* #undef size_t */
133 |
134 | /* Define to `int' if does not define. */
135 | /* #undef ssize_t */
136 |
--------------------------------------------------------------------------------
/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
40 | #include
41 | #endif
42 |
43 | #if 1
44 | #include
45 | #endif
46 |
47 | #if 1
48 | #include
49 | #endif
50 |
51 | #define SNAPPY_MAJOR 1
52 | #define SNAPPY_MINOR 1
53 | #define SNAPPY_PATCHLEVEL 4
54 | #define SNAPPY_VERSION \
55 | ((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL)
56 |
57 | #include
58 |
59 | namespace snappy {
60 |
61 | #if 1
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
80 |
81 | typedef std::string string;
82 |
83 | #ifndef DISALLOW_COPY_AND_ASSIGN
84 | #define DISALLOW_COPY_AND_ASSIGN(TypeName) \
85 | TypeName(const TypeName&); \
86 | void operator=(const TypeName&)
87 | #endif
88 |
89 | #if !1
90 | // Windows does not have an iovec type, yet the concept is universally useful.
91 | // It is simple to define it ourselves, so we put it inside our own namespace.
92 | struct iovec {
93 | void* iov_base;
94 | size_t iov_len;
95 | };
96 | #endif
97 |
98 | } // namespace snappy
99 |
100 | #endif // THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_
101 |
--------------------------------------------------------------------------------
/deps/snappy/win32/config.h:
--------------------------------------------------------------------------------
1 | #include
2 | typedef SSIZE_T ssize_t;
3 |
4 | /* Define to 1 if you have the header file. */
5 | #define HAVE_WINDOWS_H 1
6 |
7 | /* Name of package */
8 | #define PACKAGE "snappy"
9 |
10 | /* Define to the address where bug reports for this package should be sent. */
11 | #define PACKAGE_BUGREPORT ""
12 |
13 | /* Define to the full name of this package. */
14 | #define PACKAGE_NAME "snappy"
15 |
16 | /* Define to the full name and version of this package. */
17 | #define PACKAGE_STRING "snappy 1.1.4"
18 |
19 | /* Define to the one symbol short name of this package. */
20 | #define PACKAGE_TARNAME "snappy"
21 |
22 | /* Define to the version of this package. */
23 | #define PACKAGE_VERSION "1.1.4"
24 |
25 | /* Define to 1 if you have the ANSI C header files. */
26 | #define STDC_HEADERS 1
27 |
28 | /* Version number of package */
29 | #define VERSION "1.1.4"
30 |
--------------------------------------------------------------------------------
/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 0
40 | #include
41 | #endif
42 |
43 | #if 1
44 | #include
45 | #endif
46 |
47 | #if 0
48 | #include
49 | #endif
50 |
51 | #define SNAPPY_MAJOR 1
52 | #define SNAPPY_MINOR 1
53 | #define SNAPPY_PATCHLEVEL 4
54 | #define SNAPPY_VERSION \
55 | ((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL)
56 |
57 | #include
58 |
59 | namespace snappy {
60 |
61 | #if 0
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
80 |
81 | typedef std::string string;
82 |
83 | #ifndef DISALLOW_COPY_AND_ASSIGN
84 | #define DISALLOW_COPY_AND_ASSIGN(TypeName) \
85 | TypeName(const TypeName&); \
86 | void operator=(const TypeName&)
87 | #endif
88 |
89 | #if !0
90 | // Windows does not have an iovec type, yet the concept is universally useful.
91 | // It is simple to define it ourselves, so we put it inside our own namespace.
92 | struct iovec {
93 | void* iov_base;
94 | size_t iov_len;
95 | };
96 | #endif
97 |
98 | } // namespace snappy
99 |
100 | #endif // THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_
101 |
--------------------------------------------------------------------------------
/iterator.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | const util = require('util')
4 | const AbstractIterator = require('abstract-leveldown').AbstractIterator
5 | const binding = require('./binding')
6 |
7 | function Iterator (db, options) {
8 | AbstractIterator.call(this, db)
9 |
10 | this.context = binding.iterator_init(db.context, options)
11 | this.cache = null
12 | this.finished = false
13 | }
14 |
15 | util.inherits(Iterator, AbstractIterator)
16 |
17 | Iterator.prototype._seek = function (target) {
18 | if (target.length === 0) {
19 | throw new Error('cannot seek() to an empty target')
20 | }
21 |
22 | this.cache = null
23 | binding.iterator_seek(this.context, target)
24 | this.finished = false
25 | }
26 |
27 | Iterator.prototype._next = function (callback) {
28 | if (this.cache && this.cache.length) {
29 | process.nextTick(callback, null, this.cache.pop(), this.cache.pop())
30 | } else if (this.finished) {
31 | process.nextTick(callback)
32 | } else {
33 | binding.iterator_next(this.context, (err, array, finished) => {
34 | if (err) return callback(err)
35 |
36 | this.cache = array
37 | this.finished = finished
38 | this._next(callback)
39 | })
40 | }
41 |
42 | return this
43 | }
44 |
45 | Iterator.prototype._end = function (callback) {
46 | delete this.cache
47 | binding.iterator_end(this.context, callback)
48 | }
49 |
50 | module.exports = Iterator
51 |
--------------------------------------------------------------------------------
/leveldown.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | const util = require('util')
4 | const AbstractLevelDOWN = require('abstract-leveldown').AbstractLevelDOWN
5 | const binding = require('./binding')
6 | const ChainedBatch = require('./chained-batch')
7 | const Iterator = require('./iterator')
8 |
9 | function LevelDOWN (location) {
10 | if (!(this instanceof LevelDOWN)) {
11 | return new LevelDOWN(location)
12 | }
13 |
14 | if (typeof location !== 'string') {
15 | throw new Error('constructor requires a location string argument')
16 | }
17 |
18 | AbstractLevelDOWN.call(this, {
19 | bufferKeys: true,
20 | snapshots: true,
21 | permanence: true,
22 | seek: true,
23 | clear: true,
24 | getMany: true,
25 | createIfMissing: true,
26 | errorIfExists: true,
27 | additionalMethods: {
28 | approximateSize: true,
29 | compactRange: true
30 | }
31 | })
32 |
33 | this.location = location
34 | this.context = binding.db_init()
35 | }
36 |
37 | util.inherits(LevelDOWN, AbstractLevelDOWN)
38 |
39 | LevelDOWN.prototype._open = function (options, callback) {
40 | binding.db_open(this.context, this.location, options, callback)
41 | }
42 |
43 | LevelDOWN.prototype._close = function (callback) {
44 | binding.db_close(this.context, callback)
45 | }
46 |
47 | LevelDOWN.prototype._serializeKey = function (key) {
48 | return Buffer.isBuffer(key) ? key : String(key)
49 | }
50 |
51 | LevelDOWN.prototype._serializeValue = function (value) {
52 | return Buffer.isBuffer(value) ? value : String(value)
53 | }
54 |
55 | LevelDOWN.prototype._put = function (key, value, options, callback) {
56 | binding.db_put(this.context, key, value, options, callback)
57 | }
58 |
59 | LevelDOWN.prototype._get = function (key, options, callback) {
60 | binding.db_get(this.context, key, options, callback)
61 | }
62 |
63 | LevelDOWN.prototype._getMany = function (keys, options, callback) {
64 | binding.db_get_many(this.context, keys, options, callback)
65 | }
66 |
67 | LevelDOWN.prototype._del = function (key, options, callback) {
68 | binding.db_del(this.context, key, options, callback)
69 | }
70 |
71 | LevelDOWN.prototype._clear = function (options, callback) {
72 | binding.db_clear(this.context, options, callback)
73 | }
74 |
75 | LevelDOWN.prototype._chainedBatch = function () {
76 | return new ChainedBatch(this)
77 | }
78 |
79 | LevelDOWN.prototype._batch = function (operations, options, callback) {
80 | binding.batch_do(this.context, operations, options, callback)
81 | }
82 |
83 | LevelDOWN.prototype.approximateSize = function (start, end, callback) {
84 | if (start == null ||
85 | end == null ||
86 | typeof start === 'function' ||
87 | typeof end === 'function') {
88 | throw new Error('approximateSize() requires valid `start` and `end` arguments')
89 | }
90 |
91 | if (typeof callback !== 'function') {
92 | throw new Error('approximateSize() requires a callback argument')
93 | }
94 |
95 | start = this._serializeKey(start)
96 | end = this._serializeKey(end)
97 |
98 | binding.db_approximate_size(this.context, start, end, callback)
99 | }
100 |
101 | LevelDOWN.prototype.compactRange = function (start, end, callback) {
102 | if (start == null ||
103 | end == null ||
104 | typeof start === 'function' ||
105 | typeof end === 'function') {
106 | throw new Error('compactRange() requires valid `start` and `end` arguments')
107 | }
108 |
109 | if (typeof callback !== 'function') {
110 | throw new Error('compactRange() requires a callback argument')
111 | }
112 |
113 | start = this._serializeKey(start)
114 | end = this._serializeKey(end)
115 |
116 | binding.db_compact_range(this.context, start, end, callback)
117 | }
118 |
119 | LevelDOWN.prototype.getProperty = function (property) {
120 | if (typeof property !== 'string') {
121 | throw new Error('getProperty() requires a valid `property` argument')
122 | }
123 |
124 | return binding.db_get_property(this.context, property)
125 | }
126 |
127 | LevelDOWN.prototype._iterator = function (options) {
128 | if (this.status !== 'open') {
129 | // Prevent segfault
130 | throw new Error('cannot call iterator() before open()')
131 | }
132 |
133 | return new Iterator(this, options)
134 | }
135 |
136 | LevelDOWN.destroy = function (location, callback) {
137 | if (arguments.length < 2) {
138 | throw new Error('destroy() requires `location` and `callback` arguments')
139 | }
140 | if (typeof location !== 'string') {
141 | throw new Error('destroy() requires a location string argument')
142 | }
143 | if (typeof callback !== 'function') {
144 | throw new Error('destroy() requires a callback function argument')
145 | }
146 |
147 | binding.destroy_db(location, callback)
148 | }
149 |
150 | LevelDOWN.repair = function (location, callback) {
151 | if (arguments.length < 2) {
152 | throw new Error('repair() requires `location` and `callback` arguments')
153 | }
154 | if (typeof location !== 'string') {
155 | throw new Error('repair() requires a location string argument')
156 | }
157 | if (typeof callback !== 'function') {
158 | throw new Error('repair() requires a callback function argument')
159 | }
160 |
161 | binding.repair_db(location, callback)
162 | }
163 |
164 | module.exports = LevelDOWN
165 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "rocksdb",
3 | "version": "5.2.1",
4 | "description": "A low-level Node.js RocksDB binding",
5 | "license": "MIT",
6 | "main": "leveldown.js",
7 | "scripts": {
8 | "install": "node-gyp-build",
9 | "test": "standard && hallmark && (nyc -s tape test/*-test.js | faucet) && nyc report",
10 | "test-gc": "node --expose-gc test/gc.js",
11 | "test-electron": "electron test/electron.js",
12 | "test-prebuild": "cross-env PREBUILDS_ONLY=1 npm t",
13 | "coverage": "nyc report -r lcovonly",
14 | "rebuild": "npm run install --build-from-source",
15 | "prebuild": "prebuildify -t 8.14.0 --napi --strip",
16 | "prebuild-linux-x64": "prebuildify-cross -i centos7-devtoolset7 -i alpine -t 8.14.0 --napi --strip",
17 | "prebuild-darwin-x64+arm64": "prebuildify -t 8.14.0 --napi --strip --arch x64+arm64",
18 | "prebuild-win32-x64": "prebuildify -t 8.14.0 --napi --strip",
19 | "download-prebuilds": "prebuildify-ci download",
20 | "hallmark": "hallmark fix",
21 | "dependency-check": "dependency-check --no-dev -i napi-macros . test/*.js",
22 | "prepublishOnly": "npm run dependency-check"
23 | },
24 | "dependencies": {
25 | "abstract-leveldown": "^7.2.0",
26 | "napi-macros": "^2.0.0",
27 | "node-gyp-build": "^4.3.0"
28 | },
29 | "devDependencies": {
30 | "async-each": "^1.0.3",
31 | "cross-env": "^7.0.3",
32 | "delayed": "^2.0.0",
33 | "dependency-check": "^4.1.0",
34 | "du": "^1.0.0",
35 | "electron": "^19.0.2",
36 | "faucet": "^0.0.1",
37 | "glob": "^8.0.1",
38 | "hallmark": "^4.0.0",
39 | "level-concat-iterator": "^3.0.0",
40 | "mkfiletree": "^2.0.0",
41 | "node-gyp": "^8.4.1",
42 | "nyc": "^15.0.0",
43 | "prebuildify": "^5.0.0",
44 | "prebuildify-ci": "^1.0.4",
45 | "prebuildify-cross": "^5.0.0",
46 | "readfiletree": "^1.0.0",
47 | "rimraf": "^3.0.0",
48 | "standard": "^16.0.3",
49 | "tape": "^5.0.1",
50 | "tempy": "^1.0.1"
51 | },
52 | "standard": {
53 | "ignore": [
54 | "deps/*"
55 | ]
56 | },
57 | "gypfile": true,
58 | "repository": {
59 | "type": "git",
60 | "url": "https://github.com/Level/rocksdb.git"
61 | },
62 | "homepage": "https://github.com/Level/rocksdb",
63 | "keywords": [
64 | "leveldb",
65 | "level"
66 | ],
67 | "engines": {
68 | "node": ">=10.12.0"
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/test/abstract-leveldown-test.js:
--------------------------------------------------------------------------------
1 | require('abstract-leveldown/test')(require('./common'))
2 |
--------------------------------------------------------------------------------
/test/approximate-size-test.js:
--------------------------------------------------------------------------------
1 | const test = require('tape')
2 | const testCommon = require('./common')
3 |
4 | let db
5 |
6 | test('setUp common for approximate size', testCommon.setUp)
7 |
8 | test('setUp db', function (t) {
9 | db = testCommon.factory()
10 | db.open(t.end.bind(t))
11 | })
12 |
13 | test('test argument-less approximateSize() throws', function (t) {
14 | t.throws(
15 | db.approximateSize.bind(db)
16 | , /^Error: approximateSize\(\) requires valid `start` and `end` arguments/
17 | , 'no-arg approximateSize() throws'
18 | )
19 | t.end()
20 | })
21 |
22 | test('test callback-less, 1-arg, approximateSize() throws', function (t) {
23 | t.throws(
24 | db.approximateSize.bind(db, 'foo')
25 | , /^Error: approximateSize\(\) requires valid `start` and `end` arguments/
26 | , 'callback-less, 1-arg approximateSize() throws'
27 | )
28 | t.end()
29 | })
30 |
31 | test('test callback-less, 2-arg, approximateSize() throws', function (t) {
32 | t.throws(
33 | db.approximateSize.bind(db, 'foo', 'bar')
34 | , /^Error: approximateSize\(\) requires a callback argument/
35 | , 'callback-less, 2-arg approximateSize() throws'
36 | )
37 | t.end()
38 | })
39 |
40 | test('test callback-less, 3-arg, approximateSize() throws', function (t) {
41 | t.throws(
42 | db.approximateSize.bind(db, function () {})
43 | , /^Error: approximateSize\(\) requires valid `start` and `end` arguments/
44 | , 'callback-only approximateSize() throws'
45 | )
46 | t.end()
47 | })
48 |
49 | test('test callback-only approximateSize() throws', function (t) {
50 | t.throws(
51 | db.approximateSize.bind(db, function () {})
52 | , /^Error: approximateSize\(\) requires valid `start` and `end` arguments/
53 | , 'callback-only approximateSize() throws'
54 | )
55 | t.end()
56 | })
57 |
58 | test('test 1-arg + callback approximateSize() throws', function (t) {
59 | t.throws(
60 | db.approximateSize.bind(db, 'foo', function () {})
61 | , /^Error: approximateSize\(\) requires valid `start` and `end` arguments/
62 | , '1-arg + callback approximateSize() throws'
63 | )
64 | t.end()
65 | })
66 |
67 | test('test custom _serialize*', function (t) {
68 | t.plan(4)
69 | const db = testCommon.factory()
70 | db._serializeKey = function (data) { return data }
71 | db.approximateSize = function (start, end, callback) {
72 | t.deepEqual(start, { foo: 'bar' })
73 | t.deepEqual(end, { beep: 'boop' })
74 | process.nextTick(callback)
75 | }
76 | db.open(function () {
77 | db.approximateSize({ foo: 'bar' }, { beep: 'boop' }, function (err) {
78 | t.error(err)
79 | db.close(t.error.bind(t))
80 | })
81 | })
82 | })
83 |
84 | test('test approximateSize()', function (t) {
85 | const data = Array.apply(null, Array(10000)).map(function () {
86 | return 'aaaaaaaaaa'
87 | }).join('')
88 |
89 | db.batch(Array.apply(null, Array(10)).map(function (x, i) {
90 | return { type: 'put', key: 'foo' + i, value: data }
91 | }), function (err) {
92 | t.error(err)
93 |
94 | // cycle open/close to ensure a pack to .sst
95 |
96 | db.close(function (err) {
97 | t.error(err)
98 |
99 | db.open(function (err) {
100 | t.error(err)
101 |
102 | db.approximateSize('!', '~', function (err, size) {
103 | t.error(err)
104 |
105 | t.equal(typeof size, 'number')
106 | // account for snappy compression, original would be ~100000
107 | t.ok(size > 40000, 'size reports a reasonable amount (' + size + ')')
108 | t.end()
109 | })
110 | })
111 | })
112 | })
113 | })
114 |
115 | test('tearDown', function (t) {
116 | db.close(testCommon.tearDown.bind(null, t))
117 | })
118 |
--------------------------------------------------------------------------------
/test/chained-batch-gc-test.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | const test = require('tape')
4 | const testCommon = require('./common')
5 |
6 | // When we have a chained batch object without a reference, V8 might GC it
7 | // before we get a chance to (asynchronously) write the batch.
8 | test('chained batch without ref does not get GCed before write', function (t) {
9 | t.plan(2)
10 |
11 | const db = testCommon.factory()
12 |
13 | db.open(function (err) {
14 | t.ifError(err, 'no open error')
15 |
16 | let batch = db.batch()
17 |
18 | for (let i = 0; i < 1e3; i++) {
19 | batch.put(String(i), 'value')
20 | }
21 |
22 | // The sync option makes the operation slower and thus more likely to
23 | // cause a segfault (if the batch were to be GC-ed before it is written).
24 | batch.write({ sync: true }, function (err) {
25 | t.ifError(err, 'no error from write()')
26 | })
27 |
28 | // Remove reference
29 | batch = null
30 |
31 | if (global.gc) {
32 | // This is the reliable way to trigger GC (and the bug if it exists).
33 | // Useful for manual testing with "node --expose-gc".
34 | global.gc()
35 | }
36 | })
37 | })
38 |
--------------------------------------------------------------------------------
/test/cleanup-hanging-iterators-test.js:
--------------------------------------------------------------------------------
1 | const makeTest = require('./make')
2 | const repeats = 200
3 |
4 | makeTest('test ended iterator', function (db, t, done) {
5 | // First test normal and proper usage: calling it.end() before db.close()
6 | const it = db.iterator({ keyAsBuffer: false, valueAsBuffer: false })
7 |
8 | it.next(function (err, key, value) {
9 | t.ifError(err, 'no error from next()')
10 | t.equal(key, 'one', 'correct key')
11 | t.equal(value, '1', 'correct value')
12 | it.end(function (err) {
13 | t.ifError(err, 'no error from end()')
14 | done()
15 | })
16 | })
17 | })
18 |
19 | makeTest('test likely-ended iterator', function (db, t, done) {
20 | // Test improper usage: not calling it.end() before db.close(). Cleanup of the
21 | // database will crash Node if not handled properly.
22 | const it = db.iterator({ keyAsBuffer: false, valueAsBuffer: false })
23 |
24 | it.next(function (err, key, value) {
25 | t.ifError(err, 'no error from next()')
26 | t.equal(key, 'one', 'correct key')
27 | t.equal(value, '1', 'correct value')
28 | done()
29 | })
30 | })
31 |
32 | makeTest('test non-ended iterator', function (db, t, done) {
33 | // Same as the test above but with a highWaterMark of 0 so that we don't
34 | // preemptively fetch all records, to ensure that the iterator is still
35 | // active when we (attempt to) close the database.
36 | const it = db.iterator({
37 | highWaterMark: 0,
38 | keyAsBuffer: false,
39 | valueAsBuffer: false
40 | })
41 |
42 | it.next(function (err, key, value) {
43 | t.ifError(err, 'no error from next()')
44 | t.equal(key, 'one', 'correct key')
45 | t.equal(value, '1', 'correct value')
46 | done()
47 | })
48 | })
49 |
50 | makeTest('test multiple likely-ended iterators', function (db, t, done) {
51 | // Same as the test above but repeated and with an extra iterator that is not
52 | // nexting, which means its EndWorker will be executed almost immediately.
53 | for (let i = 0; i < repeats; i++) {
54 | db.iterator()
55 | db.iterator().next(function () {})
56 | }
57 |
58 | setTimeout(done, Math.floor(Math.random() * 50))
59 | })
60 |
61 | makeTest('test multiple non-ended iterators', function (db, t, done) {
62 | // Same as the test above but with a highWaterMark of 0.
63 | for (let i = 0; i < repeats; i++) {
64 | db.iterator({ highWaterMark: 0 })
65 | db.iterator({ highWaterMark: 0 }).next(function () {})
66 | }
67 |
68 | setTimeout(done, Math.floor(Math.random() * 50))
69 | })
70 |
71 | global.gc && makeTest('test multiple non-ended iterators with forced gc', function (db, t, done) {
72 | // Same as the test above but with forced GC, to test that the lifespan of an
73 | // iterator is tied to *both* its JS object and whether the iterator was ended.
74 | for (let i = 0; i < repeats; i++) {
75 | db.iterator({ highWaterMark: 0 })
76 | db.iterator({ highWaterMark: 0 }).next(function () {})
77 | }
78 |
79 | setTimeout(function () {
80 | global.gc()
81 | done()
82 | }, Math.floor(Math.random() * 50))
83 | })
84 |
85 | makeTest('test ending iterators', function (db, t, done) {
86 | // At least one end() should be in progress when we try to close the db.
87 | const it1 = db.iterator().next(function () {
88 | it1.end(function () {})
89 | })
90 | const it2 = db.iterator().next(function () {
91 | it2.end(function () {})
92 | done()
93 | })
94 | })
95 |
96 | makeTest('test recursive next', function (db, t, done) {
97 | // Test that we're able to close when user keeps scheduling work
98 | const it = db.iterator({ highWaterMark: 0 })
99 |
100 | it.next(function loop (err, key) {
101 | if (err && err.message !== 'iterator has ended') throw err
102 | if (key !== undefined) it.next(loop)
103 | })
104 |
105 | done()
106 | })
107 |
108 | makeTest('test recursive next (random)', function (db, t, done) {
109 | // Same as the test above but closing at a random time
110 | const it = db.iterator({ highWaterMark: 0 })
111 |
112 | it.next(function loop (err, key) {
113 | if (err && err.message !== 'iterator has ended') throw err
114 | if (key !== undefined) it.next(loop)
115 | })
116 |
117 | setTimeout(done, Math.floor(Math.random() * 50))
118 | })
119 |
--------------------------------------------------------------------------------
/test/clear-gc-test.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | const test = require('tape')
4 | const testCommon = require('./common')
5 | const sourceData = []
6 |
7 | for (let i = 0; i < 1e3; i++) {
8 | sourceData.push({
9 | type: 'put',
10 | key: i.toString(),
11 | value: Math.random().toString()
12 | })
13 | }
14 |
15 | test('db without ref does not get GCed while clear() is in progress', function (t) {
16 | t.plan(4)
17 |
18 | let db = testCommon.factory()
19 |
20 | db.open(function (err) {
21 | t.ifError(err, 'no open error')
22 |
23 | // Insert test data
24 | db.batch(sourceData.slice(), function (err) {
25 | t.ifError(err, 'no batch error')
26 |
27 | // Start async work
28 | db.clear(function () {
29 | t.pass('got callback')
30 |
31 | // Give GC another chance to run, to rule out other issues.
32 | setImmediate(function () {
33 | if (global.gc) global.gc()
34 | t.pass()
35 | })
36 | })
37 |
38 | // Remove reference. The db should not get garbage collected
39 | // until after the clear() callback, thanks to a napi_ref.
40 | db = null
41 |
42 | // Useful for manual testing with "node --expose-gc".
43 | // The pending tap assertion may also allow GC to kick in.
44 | if (global.gc) global.gc()
45 | })
46 | })
47 | })
48 |
--------------------------------------------------------------------------------
/test/common.js:
--------------------------------------------------------------------------------
1 | const test = require('tape')
2 | const tempy = require('tempy')
3 | const leveldown = require('..')
4 | const suite = require('abstract-leveldown/test')
5 |
6 | module.exports = suite.common({
7 | test: test,
8 | factory: function () {
9 | return leveldown(tempy.directory())
10 | },
11 |
12 | // Opt-in to new tests
13 | clear: true,
14 | getMany: true
15 | })
16 |
--------------------------------------------------------------------------------
/test/compact-range-test.js:
--------------------------------------------------------------------------------
1 | const test = require('tape')
2 | const testCommon = require('./common')
3 |
4 | let db
5 |
6 | test('setUp common', testCommon.setUp)
7 |
8 | test('setUp db', function (t) {
9 | db = testCommon.factory()
10 | db.open(t.end.bind(t))
11 | })
12 |
13 | test('test compactRange() frees disk space after key deletion', function (t) {
14 | const key1 = '000000'
15 | const key2 = '000001'
16 | const val1 = Buffer.allocUnsafe(64).fill(1)
17 | const val2 = Buffer.allocUnsafe(64).fill(1)
18 |
19 | db.batch().put(key1, val1).put(key2, val2).write(function (err) {
20 | t.ifError(err, 'no batch put error')
21 |
22 | db.compactRange(key1, key2, function (err) {
23 | t.ifError(err, 'no compactRange1 error')
24 |
25 | db.approximateSize('0', 'z', function (err, sizeAfterPuts) {
26 | t.error(err, 'no approximateSize1 error')
27 |
28 | db.batch().del(key1).del(key2).write(function (err) {
29 | t.ifError(err, 'no batch del error')
30 |
31 | db.compactRange(key1, key2, function (err) {
32 | t.ifError(err, 'no compactRange2 error')
33 |
34 | db.approximateSize('0', 'z', function (err, sizeAfterCompact) {
35 | t.error(err, 'no approximateSize2 error')
36 | t.ok(sizeAfterCompact < sizeAfterPuts)
37 | t.end()
38 | })
39 | })
40 | })
41 | })
42 | })
43 | })
44 | })
45 |
46 | test('test compactRange() serializes start and end', function (t) {
47 | t.plan(3)
48 |
49 | const clone = Object.create(db)
50 | let count = 0
51 |
52 | clone._serializeKey = function (key) {
53 | t.is(key, count++)
54 | return db._serializeKey(key)
55 | }
56 |
57 | clone.compactRange(0, 1, function (err) {
58 | t.ifError(err, 'no compactRange error')
59 | })
60 | })
61 |
62 | test('tearDown', function (t) {
63 | db.close(testCommon.tearDown.bind(null, t))
64 | })
65 |
--------------------------------------------------------------------------------
/test/compression-test.js:
--------------------------------------------------------------------------------
1 | const each = require('async-each')
2 | const du = require('du')
3 | const delayed = require('delayed')
4 | const testCommon = require('./common')
5 | const leveldown = require('..')
6 | const test = require('tape')
7 |
8 | const compressableData = Buffer.from(Array.apply(null, Array(1024 * 100)).map(function () {
9 | return 'aaaaaaaaaa'
10 | }).join(''))
11 |
12 | const multiples = 10
13 | const dataSize = compressableData.length * multiples
14 |
15 | const verify = function (location, compression, t) {
16 | du(location, function (err, size) {
17 | t.error(err)
18 | if (compression) {
19 | t.ok(size < dataSize, 'on-disk size (' + size + ') is less than data size (' + dataSize + ')')
20 | } else {
21 | t.ok(size >= dataSize, 'on-disk size (' + size + ') is greater than data size (' + dataSize + ')')
22 | }
23 | t.end()
24 | })
25 | }
26 |
27 | // close, open, close again.. 'compaction' is also performed on open()s
28 | const cycle = function (db, compression, t, callback) {
29 | const location = db.location
30 | db.close(function (err) {
31 | t.error(err)
32 | db = leveldown(location)
33 | db.open({ errorIfExists: false, compression: compression }, function () {
34 | t.error(err)
35 | db.close(function (err) {
36 | t.error(err)
37 | callback()
38 | })
39 | })
40 | })
41 | }
42 |
43 | test('compression', function (t) {
44 | t.plan(4)
45 | t.test('set up', testCommon.setUp)
46 |
47 | t.test('test data is compressed by default (db.put())', function (t) {
48 | const db = testCommon.factory()
49 | db.open(function (err) {
50 | t.error(err)
51 | each(
52 | Array.apply(null, Array(multiples)).map(function (e, i) {
53 | return [i, compressableData]
54 | }), function (args, callback) {
55 | db.put.apply(db, args.concat([callback]))
56 | }, cycle.bind(null, db, true, t, delayed.delayed(verify.bind(null, db.location, true, t), 0.01))
57 | )
58 | })
59 | })
60 |
61 | t.test('test data is not compressed with compression=false on open() (db.put())', function (t) {
62 | const db = testCommon.factory()
63 | db.open({ compression: false }, function (err) {
64 | t.error(err)
65 | each(
66 | Array.apply(null, Array(multiples)).map(function (e, i) {
67 | return [i, compressableData]
68 | }), function (args, callback) {
69 | db.put.apply(db, args.concat([callback]))
70 | }, cycle.bind(null, db, false, t, delayed.delayed(verify.bind(null, db.location, false, t), 0.01))
71 | )
72 | })
73 | })
74 |
75 | t.test('test data is compressed by default (db.batch())', function (t) {
76 | const db = testCommon.factory()
77 | db.open(function (err) {
78 | t.error(err)
79 | db.batch(
80 | Array.apply(null, Array(multiples)).map(function (e, i) {
81 | return { type: 'put', key: i, value: compressableData }
82 | }), cycle.bind(null, db, true, t, delayed.delayed(verify.bind(null, db.location, true, t), 0.01))
83 | )
84 | })
85 | })
86 | })
87 |
--------------------------------------------------------------------------------
/test/destroy-test.js:
--------------------------------------------------------------------------------
1 | const test = require('tape')
2 | const tempy = require('tempy')
3 | const fs = require('fs')
4 | const path = require('path')
5 | const mkfiletree = require('mkfiletree')
6 | const readfiletree = require('readfiletree')
7 | const rimraf = require('rimraf')
8 | const leveldown = require('..')
9 | const makeTest = require('./make')
10 |
11 | test('test argument-less destroy() throws', function (t) {
12 | t.throws(leveldown.destroy, {
13 | name: 'Error',
14 | message: 'destroy() requires `location` and `callback` arguments'
15 | }, 'no-arg destroy() throws')
16 | t.end()
17 | })
18 |
19 | test('test callback-less, 1-arg, destroy() throws', function (t) {
20 | t.throws(leveldown.destroy.bind(null, 'foo'), {
21 | name: 'Error',
22 | message: 'destroy() requires `location` and `callback` arguments'
23 | }, 'callback-less, 1-arg destroy() throws')
24 | t.end()
25 | })
26 |
27 | test('test destroy non-existent directory', function (t) {
28 | t.plan(4)
29 |
30 | const location = tempy.directory()
31 | const parent = path.dirname(location)
32 |
33 | // For symmetry with the opposite test below.
34 | t.ok(fs.existsSync(parent), 'parent exists before')
35 |
36 | // Cleanup to avoid conflicts with other tests
37 | rimraf(location, { glob: false }, function (err) {
38 | t.ifError(err, 'no error from rimraf()')
39 |
40 | leveldown.destroy(location, function (err) {
41 | // This behavior differs from LevelDB, which is silent.
42 | t.ok(/.*IO error.*/.test(err), 'got IO error')
43 |
44 | // Assert that destroy() didn't inadvertently create the directory.
45 | // Or if it did, that it was at least cleaned up afterwards.
46 | t.notOk(fs.existsSync(location), 'directory does not exist after')
47 | })
48 | })
49 | })
50 |
51 | test('test destroy non-existent parent directory', function (t) {
52 | t.plan(3)
53 |
54 | const location = '/1/2/3/4'
55 | const parent = path.dirname(location)
56 |
57 | t.notOk(fs.existsSync(parent), 'parent does not exist before')
58 |
59 | leveldown.destroy(location, function (err) {
60 | // This behavior differs from LevelDB, which is silent.
61 | t.ok(/.*IO error.*\/1\/2\/3\/4\/LOCK.*/.test(err), 'got IO error')
62 | t.notOk(fs.existsSync(location), 'directory does not exist after')
63 | })
64 | })
65 |
66 | test('test destroy non leveldb directory', function (t) {
67 | const tree = {
68 | foo: 'FOO',
69 | bar: { one: 'ONE', two: 'TWO', three: 'THREE' }
70 | }
71 |
72 | mkfiletree.makeTemp('destroy-test', tree, function (err, dir) {
73 | t.ifError(err, 'no error from makeTemp()')
74 |
75 | leveldown.destroy(dir, function (err) {
76 | t.ifError(err, 'no error from destroy()')
77 |
78 | readfiletree(dir, function (err, actual) {
79 | t.ifError(err, 'no error from readfiletree()')
80 | t.deepEqual(actual, tree, 'directory remains untouched')
81 |
82 | mkfiletree.cleanUp(function (err) {
83 | t.ifError(err, 'no error from cleanup()')
84 | t.end()
85 | })
86 | })
87 | })
88 | })
89 | })
90 |
91 | makeTest('test destroy() cleans and removes leveldb-only dir', function (db, t, done) {
92 | const location = db.location
93 | db.close(function (err) {
94 | t.ifError(err, 'no error from close()')
95 |
96 | leveldown.destroy(location, function (err) {
97 | t.ifError(err, 'no error from destroy()')
98 | t.notOk(fs.existsSync(location), 'directory completely removed')
99 |
100 | done(null, false)
101 | })
102 | })
103 | })
104 |
105 | makeTest('test destroy() cleans and removes only leveldb parts of a dir', function (db, t, done) {
106 | const location = db.location
107 | fs.writeFileSync(path.join(location, 'foo'), 'FOO')
108 |
109 | db.close(function (err) {
110 | t.ifError(err, 'no error from close()')
111 |
112 | leveldown.destroy(location, function (err) {
113 | t.ifError(err, 'no error from destroy()')
114 |
115 | readfiletree(location, function (err, tree) {
116 | t.ifError(err, 'no error from readfiletree()')
117 | t.deepEqual(tree, { foo: 'FOO' }, 'non-leveldb files left intact')
118 |
119 | done(null, false)
120 | })
121 | })
122 | })
123 | })
124 |
--------------------------------------------------------------------------------
/test/electron.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | const tape = require('tape')
4 | const electron = require('electron')
5 | const path = require('path')
6 | const glob = require('glob')
7 | const app = electron.app
8 |
9 | process.on('uncaughtException', function (err) {
10 | console.error(err)
11 | app.exit(1)
12 | })
13 |
14 | app.on('ready', function () {
15 | tape.onFinish(() => app.quit())
16 | tape.onFailure(() => app.exit(1))
17 |
18 | for (const file of glob.sync('test/*-test.js')) {
19 | require(path.resolve('.', file))
20 | }
21 | })
22 |
--------------------------------------------------------------------------------
/test/empty-range-option-test.js:
--------------------------------------------------------------------------------
1 | const test = require('tape')
2 | const concat = require('level-concat-iterator')
3 | const testCommon = require('./common')
4 | const rangeOptions = ['gt', 'gte', 'lt', 'lte']
5 |
6 | test('empty range options are ignored', function (t) {
7 | const db = testCommon.factory()
8 |
9 | t.test('setup', function (t) {
10 | db.open(function (err) {
11 | t.ifError(err, 'no open error')
12 |
13 | db.batch()
14 | .put(Buffer.from([0]), 'value')
15 | .put(Buffer.from([126]), 'value')
16 | .write(t.end.bind(t))
17 | })
18 | })
19 |
20 | rangeOptions.forEach(function (option) {
21 | t.test(option, function (t) {
22 | t.plan(8)
23 |
24 | concat(db.iterator({ [option]: Buffer.alloc(0) }), verifyBuffer)
25 | concat(db.iterator({ [option]: Buffer.alloc(0), keyAsBuffer: false }), verifyString)
26 | concat(db.iterator({ [option]: '' }), verifyBuffer)
27 | concat(db.iterator({ [option]: '', keyAsBuffer: false }), verifyString)
28 |
29 | function verifyBuffer (err, entries) {
30 | t.ifError(err, 'no concat error')
31 | t.same(entries.map(getKey), [Buffer.from([0]), Buffer.from([126])])
32 | }
33 |
34 | function verifyString (err, entries) {
35 | t.ifError(err, 'no concat error')
36 | t.same(entries.map(getKey), ['\x00', '~'])
37 | }
38 |
39 | function getKey (entry) {
40 | return entry.key
41 | }
42 | })
43 | })
44 |
45 | t.test('teardown', function (t) {
46 | db.close(t.end.bind(t))
47 | })
48 |
49 | t.end()
50 | })
51 |
--------------------------------------------------------------------------------
/test/env-cleanup-hook-test.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | const test = require('tape')
4 | const fork = require('child_process').fork
5 | const path = require('path')
6 |
7 | // Test env_cleanup_hook at several stages of a db lifetime
8 | addTest(['create'])
9 | addTest(['create', 'open'])
10 | addTest(['create', 'open', 'create-iterator'])
11 | addTest(['create', 'open', 'create-iterator', 'close'])
12 | addTest(['create', 'open', 'create-iterator', 'nexting'])
13 | addTest(['create', 'open', 'create-iterator', 'nexting', 'close'])
14 | addTest(['create', 'open', 'close'])
15 | addTest(['create', 'open-error'])
16 |
17 | function addTest (steps) {
18 | test(`cleanup on environment exit (${steps.join(', ')})`, function (t) {
19 | t.plan(3)
20 |
21 | const child = fork(path.join(__dirname, 'env-cleanup-hook.js'), steps)
22 |
23 | child.on('message', function (m) {
24 | t.is(m, steps[steps.length - 1], `got to step: ${m}`)
25 | child.disconnect()
26 | })
27 |
28 | child.on('exit', function (code, sig) {
29 | t.is(code, 0, 'child exited normally')
30 | t.is(sig, null, 'not terminated due to signal')
31 | })
32 | })
33 | }
34 |
--------------------------------------------------------------------------------
/test/env-cleanup-hook.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | const testCommon = require('./common')
4 |
5 | function test (steps) {
6 | let step
7 |
8 | function nextStep () {
9 | step = steps.shift() || step
10 | return step
11 | }
12 |
13 | if (nextStep() !== 'create') {
14 | // Send a message triggering an environment exit
15 | // and indicating at which step we stopped.
16 | return process.send(step)
17 | }
18 |
19 | const db = testCommon.factory()
20 |
21 | if (nextStep() !== 'open') {
22 | if (nextStep() === 'open-error') {
23 | // If opening fails the cleanup hook should be a noop.
24 | db.open({ createIfMissing: false, errorIfExists: true }, function (err) {
25 | if (!err) throw new Error('Expected an open() error')
26 | })
27 | }
28 |
29 | return process.send(step)
30 | }
31 |
32 | // Open the db, expected to be closed by the cleanup hook.
33 | db.open(function (err) {
34 | if (err) throw err
35 |
36 | if (nextStep() === 'create-iterator') {
37 | // Create an iterator, expected to be ended by the cleanup hook.
38 | const it = db.iterator()
39 |
40 | if (nextStep() === 'nexting') {
41 | // This async work should finish before the cleanup hook is called.
42 | it.next(function (err) {
43 | if (err) throw err
44 | })
45 | }
46 | }
47 |
48 | if (nextStep() === 'close') {
49 | // Close the db, after which the cleanup hook is a noop.
50 | db.close(function (err) {
51 | if (err) throw err
52 | })
53 | }
54 |
55 | process.send(step)
56 | })
57 | }
58 |
59 | test(process.argv.slice(2))
60 |
--------------------------------------------------------------------------------
/test/gc.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | // A special entry point to run certain tests with forced gc.
4 |
5 | if (!global.gc) {
6 | console.error('Run with node --expose-gc')
7 | process.exit(1)
8 | }
9 |
10 | require('./cleanup-hanging-iterators-test')
11 | require('./iterator-gc-test')
12 | require('./chained-batch-gc-test')
13 | require('./clear-gc-test')
14 |
--------------------------------------------------------------------------------
/test/getproperty-test.js:
--------------------------------------------------------------------------------
1 | const test = require('tape')
2 | const testCommon = require('./common')
3 |
4 | let db
5 |
6 | test('setUp common', testCommon.setUp)
7 |
8 | test('setUp db', function (t) {
9 | db = testCommon.factory()
10 | db.open(t.end.bind(t))
11 | })
12 |
13 | test('test argument-less getProperty() throws', function (t) {
14 | t.throws(db.getProperty.bind(db), {
15 | name: 'Error',
16 | message: 'getProperty() requires a valid `property` argument'
17 | }, 'no-arg getProperty() throws')
18 | t.end()
19 | })
20 |
21 | test('test non-string getProperty() throws', function (t) {
22 | t.throws(db.getProperty.bind(db, {}), {
23 | name: 'Error',
24 | message: 'getProperty() requires a valid `property` argument'
25 | }, 'no-arg getProperty() throws')
26 | t.end()
27 | })
28 |
29 | test('test invalid getProperty() returns empty string', function (t) {
30 | t.equal(db.getProperty('foo'), '', 'invalid property')
31 | t.equal(db.getProperty('rocksdb.foo'), '', 'invalid rocksdb.* property')
32 | t.end()
33 | })
34 |
35 | test('test invalid getProperty("rocksdb.num-files-at-levelN") returns numbers', function (t) {
36 | for (let i = 0; i < 7; i++) {
37 | t.equal(db.getProperty('rocksdb.num-files-at-level' + i),
38 | '0', '"rocksdb.num-files-at-levelN" === "0"')
39 | }
40 | t.end()
41 | })
42 |
43 | test('test invalid getProperty("rocksdb.stats")', function (t) {
44 | t.ok(db.getProperty('rocksdb.stats').split('\n').length > 3, 'rocksdb.stats has > 3 newlines')
45 | t.end()
46 | })
47 |
48 | test('test invalid getProperty("rocksdb.sstables")', function (t) {
49 | const expected = [0, 1, 2, 3, 4, 5, 6].map(function (l) {
50 | return '--- level ' + l + ' --- version# 2 ---'
51 | }).join('\n') + '\n'
52 | t.equal(db.getProperty('rocksdb.sstables'), expected, 'rocksdb.sstables')
53 | t.end()
54 | })
55 |
56 | test('tearDown', function (t) {
57 | db.close(testCommon.tearDown.bind(null, t))
58 | })
59 |
--------------------------------------------------------------------------------
/test/iterator-gc-test.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | const test = require('tape')
4 | const collectEntries = require('level-concat-iterator')
5 | const testCommon = require('./common')
6 | const sourceData = []
7 |
8 | for (let i = 0; i < 1e3; i++) {
9 | sourceData.push({
10 | type: 'put',
11 | key: i.toString(),
12 | value: Math.random().toString()
13 | })
14 | }
15 |
16 | test('setUp', testCommon.setUp)
17 |
18 | // When you have a database open with an active iterator, but no references to
19 | // the db, V8 will GC the database and you'll get an failed assert from LevelDB.
20 | test('db without ref does not get GCed while iterating', function (t) {
21 | t.plan(6)
22 |
23 | let db = testCommon.factory()
24 |
25 | db.open(function (err) {
26 | t.ifError(err, 'no open error')
27 |
28 | // Insert test data
29 | db.batch(sourceData.slice(), function (err) {
30 | t.ifError(err, 'no batch error')
31 |
32 | // Set highWaterMark to 0 so that we don't preemptively fetch.
33 | const it = db.iterator({ highWaterMark: 0 })
34 |
35 | // Remove reference
36 | db = null
37 |
38 | if (global.gc) {
39 | // This is the reliable way to trigger GC (and the bug if it exists).
40 | // Useful for manual testing with "node --expose-gc".
41 | global.gc()
42 | iterate(it)
43 | } else {
44 | // But a timeout usually also allows GC to kick in. If not, the time
45 | // between iterator ticks might. That's when "highWaterMark: 0" helps.
46 | setTimeout(iterate.bind(null, it), 1000)
47 | }
48 | })
49 | })
50 |
51 | function iterate (it) {
52 | // No reference to db here, could be GCed. It shouldn't..
53 | collectEntries(it, function (err, entries) {
54 | t.ifError(err, 'no iterator error')
55 | t.is(entries.length, sourceData.length, 'got data')
56 |
57 | // Because we also have a reference on the iterator. That's the fix.
58 | t.ok(it.db, 'abstract iterator has reference to db')
59 |
60 | // Which as luck would have it, also allows us to properly end this test.
61 | it.db.close(function (err) {
62 | t.ifError(err, 'no close error')
63 | })
64 | })
65 | }
66 | })
67 |
68 | test('tearDown', testCommon.tearDown)
69 |
--------------------------------------------------------------------------------
/test/iterator-recursion-test.js:
--------------------------------------------------------------------------------
1 | const test = require('tape')
2 | const testCommon = require('./common')
3 | const fork = require('child_process').fork
4 | const path = require('path')
5 |
6 | let db
7 |
8 | const sourceData = (function () {
9 | const d = []
10 | let i = 0
11 | let k
12 | for (; i < 100000; i++) {
13 | k = (i < 10 ? '0' : '') + i
14 | d.push({
15 | type: 'put',
16 | key: k,
17 | value: Math.random()
18 | })
19 | }
20 | return d
21 | }())
22 |
23 | test('setUp common', testCommon.setUp)
24 |
25 | // TODO: fix this test. It asserted that we didn't segfault if user code had an
26 | // infinite loop leading to stack exhaustion, which caused a node::FatalException()
27 | // call in our Iterator to segfault. This was fixed in 2014 (commit 85e6a38).
28 | //
29 | // Today (2020), we see occasional failures in CI again. We no longer call
30 | // node::FatalException() so there's a new reason.
31 | test.skip('try to create an iterator with a blown stack', function (t) {
32 | for (let i = 0; i < 100; i++) {
33 | t.test(`try to create an iterator with a blown stack (${i})`, function (t) {
34 | t.plan(3)
35 |
36 | // Reducing the stack size down from the default 984 for the child node
37 | // process makes it easier to trigger the bug condition. But making it too low
38 | // causes the child process to die for other reasons.
39 | const opts = { execArgv: ['--stack-size=128'] }
40 | const child = fork(path.join(__dirname, 'stack-blower.js'), ['run'], opts)
41 |
42 | child.on('message', function (m) {
43 | t.ok(true, m)
44 | child.disconnect()
45 | })
46 |
47 | child.on('exit', function (code, sig) {
48 | t.is(code, 0, 'child exited normally')
49 | t.is(sig, null, 'not terminated due to signal')
50 | })
51 | })
52 | }
53 |
54 | t.end()
55 | })
56 |
57 | test('setUp db', function (t) {
58 | db = testCommon.factory()
59 | db.open(function (err) {
60 | t.error(err)
61 | db.batch(sourceData, t.end.bind(t))
62 | })
63 | })
64 |
65 | test('iterate over a large iterator with a large watermark', function (t) {
66 | const iterator = db.iterator({
67 | highWaterMark: 10000000
68 | })
69 | const read = function () {
70 | iterator.next(function (err, key, value) {
71 | if (err) throw err
72 |
73 | if (key === undefined && value === undefined) {
74 | t.end()
75 | } else {
76 | read()
77 | }
78 | })
79 | }
80 |
81 | read()
82 | })
83 |
84 | test('tearDown', function (t) {
85 | db.close(testCommon.tearDown.bind(null, t))
86 | })
87 |
--------------------------------------------------------------------------------
/test/iterator-starvation-test.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | const test = require('tape')
4 | const testCommon = require('./common')
5 | const sourceData = []
6 |
7 | // For this test the number of records in the db must be a multiple of
8 | // the hardcoded fast-future limit (1000) or a cache size limit in C++.
9 | for (let i = 0; i < 1e4; i++) {
10 | sourceData.push({
11 | type: 'put',
12 | key: i.toString(),
13 | value: ''
14 | })
15 | }
16 |
17 | test('setUp', testCommon.setUp)
18 |
19 | test('iterator does not starve event loop', function (t) {
20 | t.plan(6)
21 |
22 | const db = testCommon.factory()
23 |
24 | db.open(function (err) {
25 | t.ifError(err, 'no open error')
26 |
27 | // Insert test data
28 | db.batch(sourceData.slice(), function (err) {
29 | t.ifError(err, 'no batch error')
30 |
31 | // Set a high highWaterMark to fill up the cache entirely
32 | const it = db.iterator({ highWaterMark: Math.pow(1024, 3) })
33 |
34 | let breaths = 0
35 | let entries = 0
36 | let scheduled = false
37 |
38 | // Iterate continuously while also scheduling work with setImmediate(),
39 | // which should be given a chance to run because we limit the tick depth.
40 | const next = function () {
41 | it.next(function (err, key, value) {
42 | if (err || (key === undefined && value === undefined)) {
43 | t.ifError(err, 'no next error')
44 | t.is(entries, sourceData.length, 'got all data')
45 | t.is(breaths, sourceData.length / 1000, 'breathed while iterating')
46 |
47 | return db.close(function (err) {
48 | t.ifError(err, 'no close error')
49 | })
50 | }
51 |
52 | entries++
53 |
54 | if (!scheduled) {
55 | scheduled = true
56 | setImmediate(function () {
57 | breaths++
58 | scheduled = false
59 | })
60 | }
61 |
62 | next()
63 | })
64 | }
65 |
66 | next()
67 | })
68 | })
69 | })
70 |
71 | test('iterator with seeks does not starve event loop', function (t) {
72 | t.plan(6)
73 |
74 | const db = testCommon.factory()
75 |
76 | db.open(function (err) {
77 | t.ifError(err, 'no open error')
78 |
79 | db.batch(sourceData.slice(), function (err) {
80 | t.ifError(err, 'no batch error')
81 |
82 | const it = db.iterator({ highWaterMark: Math.pow(1024, 3), limit: sourceData.length })
83 |
84 | let breaths = 0
85 | let entries = 0
86 | let scheduled = false
87 |
88 | const next = function () {
89 | it.next(function (err, key, value) {
90 | if (err || (key === undefined && value === undefined)) {
91 | t.ifError(err, 'no next error')
92 | t.is(entries, sourceData.length, 'got all data')
93 | t.is(breaths, sourceData.length, 'breathed while iterating')
94 |
95 | return db.close(function (err) {
96 | t.ifError(err, 'no close error')
97 | })
98 | }
99 |
100 | entries++
101 |
102 | if (!scheduled) {
103 | // Seeking clears the cache, which should only have a positive
104 | // effect because it means the cache must be refilled, which
105 | // again gives us time to breathe. This is a smoke test, really.
106 | it.seek(sourceData[0].key)
107 |
108 | scheduled = true
109 | setImmediate(function () {
110 | breaths++
111 | scheduled = false
112 | })
113 | }
114 |
115 | next()
116 | })
117 | }
118 |
119 | next()
120 | })
121 | })
122 | })
123 |
124 | test('tearDown', testCommon.tearDown)
125 |
--------------------------------------------------------------------------------
/test/iterator-test.js:
--------------------------------------------------------------------------------
1 | const make = require('./make')
2 |
3 | // This test isn't included in abstract-leveldown because
4 | // the empty-check is currently performed by leveldown.
5 | make('iterator#seek throws if target is empty', function (db, t, done) {
6 | const targets = ['', Buffer.alloc(0), []]
7 | let pending = targets.length
8 |
9 | targets.forEach(function (target) {
10 | const ite = db.iterator()
11 | let error
12 |
13 | try {
14 | ite.seek(target)
15 | } catch (err) {
16 | error = err.message
17 | }
18 |
19 | t.is(error, 'cannot seek() to an empty target', 'got error')
20 | ite.end(end)
21 | })
22 |
23 | function end (err) {
24 | t.ifError(err, 'no error from end()')
25 | if (!--pending) done()
26 | }
27 | })
28 |
29 | make('iterator optimized for seek', function (db, t, done) {
30 | const batch = db.batch()
31 | batch.put('a', 1)
32 | batch.put('b', 1)
33 | batch.put('c', 1)
34 | batch.put('d', 1)
35 | batch.put('e', 1)
36 | batch.put('f', 1)
37 | batch.put('g', 1)
38 | batch.write(function (err) {
39 | const ite = db.iterator()
40 | t.ifError(err, 'no error from batch()')
41 | ite.next(function (err, key, value) {
42 | t.ifError(err, 'no error from next()')
43 | t.equal(key.toString(), 'a', 'key matches')
44 | t.equal(ite.cache.length, 0, 'no cache')
45 | ite.next(function (err, key, value) {
46 | t.ifError(err, 'no error from next()')
47 | t.equal(key.toString(), 'b', 'key matches')
48 | t.ok(ite.cache.length > 0, 'has cached items')
49 | ite.seek('d')
50 | t.notOk(ite.cache, 'cache is removed')
51 | ite.next(function (err, key, value) {
52 | t.ifError(err, 'no error from next()')
53 | t.equal(key.toString(), 'd', 'key matches')
54 | t.equal(ite.cache.length, 0, 'no cache')
55 | ite.next(function (err, key, value) {
56 | t.ifError(err, 'no error from next()')
57 | t.equal(key.toString(), 'e', 'key matches')
58 | t.ok(ite.cache.length > 0, 'has cached items')
59 | ite.end(done)
60 | })
61 | })
62 | })
63 | })
64 | })
65 | })
66 |
67 | make('close db with open iterator', function (db, t, done) {
68 | const ite = db.iterator()
69 | let cnt = 0
70 | let hadError = false
71 |
72 | ite.next(function loop (err, key, value) {
73 | if (cnt++ === 0) {
74 | // The first call should succeed, because it was scheduled before close()
75 | t.ifError(err, 'no error from next()')
76 | } else {
77 | // The second call should fail, because it was scheduled after close()
78 | t.equal(err.message, 'iterator has ended')
79 | hadError = true
80 | }
81 | if (key !== undefined) { ite.next(loop) }
82 | })
83 |
84 | db.close(function (err) {
85 | t.ifError(err, 'no error from close()')
86 | t.ok(hadError)
87 |
88 | done(null, false)
89 | })
90 | })
91 |
92 | make('key-only iterator', function (db, t, done) {
93 | const it = db.iterator({ values: false, keyAsBuffer: false, valueAsBuffer: false })
94 |
95 | it.next(function (err, key, value) {
96 | t.ifError(err, 'no next() error')
97 | t.is(key, 'one')
98 | t.is(value, '') // should this be undefined?
99 | it.end(done)
100 | })
101 | })
102 |
103 | make('value-only iterator', function (db, t, done) {
104 | const it = db.iterator({ keys: false, keyAsBuffer: false, valueAsBuffer: false })
105 |
106 | it.next(function (err, key, value) {
107 | t.ifError(err, 'no next() error')
108 | t.is(key, '') // should this be undefined?
109 | t.is(value, '1')
110 | it.end(done)
111 | })
112 | })
113 |
--------------------------------------------------------------------------------
/test/leak-tester-batch.js:
--------------------------------------------------------------------------------
1 | const BUFFERS = false
2 | const CHAINED = false
3 |
4 | const testCommon = require('./common')
5 | const crypto = require('crypto')
6 | const assert = require('assert')
7 |
8 | let writeCount = 0
9 | let rssBase
10 |
11 | function print () {
12 | if (writeCount % 100 === 0) {
13 | if (typeof global.gc !== 'undefined') global.gc()
14 |
15 | console.log(
16 | 'writeCount =', writeCount, ', rss =',
17 | Math.round(process.memoryUsage().rss / rssBase * 100) + '%',
18 | Math.round(process.memoryUsage().rss / 1024 / 1024) + 'M',
19 | JSON.stringify([0, 1, 2, 3, 4, 5, 6].map(function (l) {
20 | return db.getProperty('rocksdb.num-files-at-level' + l)
21 | }))
22 | )
23 | }
24 | }
25 |
26 | const run = CHAINED
27 | ? function () {
28 | const batch = db.batch()
29 |
30 | for (let i = 0; i < 100; i++) {
31 | let key = 'long key to test memory usage ' + String(Math.floor(Math.random() * 10000000))
32 | if (BUFFERS) key = Buffer.from(key)
33 | let value = crypto.randomBytes(1024)
34 | if (!BUFFERS) value = value.toString('hex')
35 | batch.put(key, value)
36 | }
37 |
38 | batch.write(function (err) {
39 | assert(!err)
40 | process.nextTick(run)
41 | })
42 |
43 | writeCount++
44 | print()
45 | }
46 | : function () {
47 | const batch = []
48 |
49 | for (let i = 0; i < 100; i++) {
50 | let key = 'long key to test memory usage ' + String(Math.floor(Math.random() * 10000000))
51 | if (BUFFERS) key = Buffer.from(key)
52 | let value = crypto.randomBytes(1024)
53 | if (!BUFFERS) value = value.toString('hex')
54 | batch.push({ type: 'put', key: key, value: value })
55 | }
56 |
57 | db.batch(batch, function (err) {
58 | assert(!err)
59 | process.nextTick(run)
60 | })
61 |
62 | writeCount++
63 | print()
64 | }
65 |
66 | const db = testCommon.factory()
67 |
68 | db.open(function () {
69 | rssBase = process.memoryUsage().rss
70 | run()
71 | })
72 |
--------------------------------------------------------------------------------
/test/leak-tester-iterator.js:
--------------------------------------------------------------------------------
1 | const db = require('./common').factory()
2 |
3 | let count = 0
4 | let rssBase
5 |
6 | if (!global.gc) {
7 | console.error('To force GC, run with "node --expose-gc"')
8 | }
9 |
10 | function run () {
11 | const it = db.iterator()
12 |
13 | it.next(function (err) {
14 | if (err) throw err
15 |
16 | it.end(function (err) {
17 | if (err) throw err
18 |
19 | if (!rssBase) {
20 | rssBase = process.memoryUsage().rss
21 | }
22 |
23 | if (++count % 1000 === 0) {
24 | if (global.gc) global.gc()
25 |
26 | const rss = process.memoryUsage().rss
27 | const percent = Math.round((rss / rssBase) * 100)
28 | const mb = Math.round(rss / 1024 / 1024)
29 |
30 | console.log('count = %d, rss = %d% %dM', count, percent, mb)
31 | }
32 |
33 | run()
34 | })
35 | })
36 | }
37 |
38 | db.open(function (err) {
39 | if (err) throw err
40 |
41 | db.put('key', 'value', function (err) {
42 | if (err) throw err
43 | run()
44 | })
45 | })
46 |
--------------------------------------------------------------------------------
/test/leak-tester.js:
--------------------------------------------------------------------------------
1 | const BUFFERS = false
2 |
3 | const testCommon = require('./common')
4 | const crypto = require('crypto')
5 |
6 | let putCount = 0
7 | let getCount = 0
8 | let rssBase
9 |
10 | function run () {
11 | let key = 'long key to test memory usage ' + String(Math.floor(Math.random() * 10000000))
12 |
13 | if (BUFFERS) key = Buffer.from(key)
14 |
15 | db.get(key, function (err, value) {
16 | getCount++
17 |
18 | if (err) {
19 | let putValue = crypto.randomBytes(1024)
20 | if (!BUFFERS) putValue = putValue.toString('hex')
21 |
22 | return db.put(key, putValue, function () {
23 | putCount++
24 | process.nextTick(run)
25 | })
26 | }
27 |
28 | process.nextTick(run)
29 | })
30 |
31 | if (getCount % 1000 === 0) {
32 | if (typeof global.gc !== 'undefined') global.gc()
33 | console.log('getCount =', getCount, ', putCount = ', putCount, ', rss =',
34 | Math.round(process.memoryUsage().rss / rssBase * 100) + '%',
35 | Math.round(process.memoryUsage().rss / 1024 / 1024) + 'M',
36 | JSON.stringify([0, 1, 2, 3, 4, 5, 6].map(function (l) {
37 | return db.getProperty('rocksdb.num-files-at-level' + l)
38 | })))
39 | }
40 | }
41 |
42 | const db = testCommon.factory()
43 |
44 | db.open(function () {
45 | rssBase = process.memoryUsage().rss
46 | run()
47 | })
48 |
--------------------------------------------------------------------------------
/test/leveldown-test.js:
--------------------------------------------------------------------------------
1 | const test = require('tape')
2 | const leveldown = require('..')
3 |
4 | test('test database creation non-string location throws', function (t) {
5 | t.throws(
6 | leveldown.bind(null, {}),
7 | /constructor requires a location string argument/,
8 | 'non-string location leveldown() throws'
9 | )
10 | t.end()
11 | })
12 |
--------------------------------------------------------------------------------
/test/make.js:
--------------------------------------------------------------------------------
1 | const test = require('tape')
2 | const testCommon = require('./common')
3 |
4 | function makeTest (name, testFn) {
5 | test(name, function (t) {
6 | const db = testCommon.factory()
7 | const done = function (err, close) {
8 | t.ifError(err, 'no error from done()')
9 |
10 | if (close === false) {
11 | t.end()
12 | return
13 | }
14 |
15 | db.close(function (err) {
16 | t.ifError(err, 'no error from close()')
17 | t.end()
18 | })
19 | }
20 | db.open(function (err) {
21 | t.ifError(err, 'no error from open()')
22 | db.batch([
23 | { type: 'put', key: 'one', value: '1' },
24 | { type: 'put', key: 'two', value: '2' },
25 | { type: 'put', key: 'three', value: '3' }
26 | ], function (err) {
27 | t.ifError(err, 'no error from batch()')
28 | testFn(db, t, done)
29 | })
30 | })
31 | })
32 | }
33 |
34 | module.exports = makeTest
35 |
--------------------------------------------------------------------------------
/test/open-read-only-test.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | const test = require('tape')
4 | const leveldown = require('..')
5 | const tempy = require('tempy')
6 | const fs = require('fs')
7 | const path = require('path')
8 |
9 | const location = tempy.directory()
10 |
11 | // This is used because it's not sufficient on windows to set a parent folder as readonly
12 | function chmodRecursive (mode) {
13 | fs.readdirSync(location).forEach(function (file) {
14 | fs.chmodSync(path.join(location, file), mode)
15 | })
16 | fs.chmodSync(location, mode)
17 | }
18 |
19 | function factory (mode) {
20 | if (mode != null) chmodRecursive(mode)
21 | return leveldown(location)
22 | }
23 |
24 | test('test write to read/write database', function (t) {
25 | const db = factory()
26 |
27 | db.open(function (err) {
28 | t.ifError(err, 'no error from open()')
29 |
30 | db.put('my key', 'my value', function (err) {
31 | t.ifError(err, 'no error from put()')
32 | db.get('my key', function (err, value) {
33 | t.ifError(err, 'no error from get()')
34 | t.equal(value.toString(), 'my value', 'correct value')
35 | db.close(t.end.bind(t))
36 | })
37 | })
38 | })
39 | })
40 |
41 | test('test throw error reading read-only database', function (t) {
42 | const db = factory(0o555)
43 |
44 | db.open(function (err) {
45 | t.ok(err, 'should get error reading read only database')
46 | t.ok(/IO Error/i.test(err && err.message), 'should get io error')
47 | db.close(t.end.bind(t))
48 | })
49 | })
50 |
51 | test('test read from a read-only database if readOnly is true', function (t) {
52 | const db = factory(0o555)
53 |
54 | db.open({ readOnly: true }, function (err) {
55 | t.ifError(err, 'no error from open()')
56 |
57 | db.get('my key', function (err, value) {
58 | t.ifError(err, 'no error from get()')
59 | t.equal(value.toString(), 'my value', 'correct value')
60 | db.close(t.end.bind(t))
61 | })
62 | })
63 | })
64 |
65 | test('test throw error reading read-only database if readOnly is false', function (t) {
66 | const db = factory(0o555)
67 |
68 | db.open({ readOnly: false }, function (err) {
69 | t.ok(err, 'should get error reading read only database')
70 | t.ok(/IO Error/i.test(err && err.message), 'should get io error')
71 | db.close(t.end.bind(t))
72 | })
73 | })
74 |
75 | test('test throw error putting data to read-only db if readOnly is true', function (t) {
76 | const db = factory(0o555)
77 |
78 | db.open({ readOnly: true }, function (err) {
79 | t.ifError(err, 'no error from open()')
80 |
81 | db.put('my key', 'my value', function (err) {
82 | t.ok(err, 'should get write error')
83 | t.ok(/Not supported operation in read only mode/i.test(err && err.message), 'should get io error')
84 | db.close(t.end.bind(t))
85 | })
86 | })
87 | })
88 |
89 | test('test throw error deleting data from read-only db if readOnly is true', function (t) {
90 | const db = factory(0o555)
91 |
92 | db.open({ readOnly: true }, function (err) {
93 | t.ifError(err, 'no error from open()')
94 |
95 | db.del('my key', function (err) {
96 | t.ok(err, 'should get write error')
97 | t.ok(/Not supported operation in read only mode/i.test(err && err.message), 'should get io error')
98 | db.close(t.end.bind(t))
99 | })
100 | })
101 | })
102 |
--------------------------------------------------------------------------------
/test/port-libuv-fix-test.js:
--------------------------------------------------------------------------------
1 | const test = require('tape')
2 | const path = require('path')
3 | const fs = require('fs')
4 |
5 | test.skip('test port-libuv is being used', function (t) {
6 | const version = fs.readFileSync(path.join(__dirname, '../deps/leveldb/leveldb.gyp'), 'utf8')
7 | .match(/"ldbversion": "([^"]+)"/)[1]
8 |
9 | t.ok(version, 'matched current leveldb version')
10 |
11 | const porth = fs.readFileSync(path.join(__dirname, '../deps/leveldb/leveldb-' + version + '/port/port.h'), 'utf8')
12 |
13 | t.ok(/"port_uv\.h"/.test(porth), 'port.h includes reference to port_uv.h')
14 |
15 | t.end()
16 | })
17 |
--------------------------------------------------------------------------------
/test/repair-test.js:
--------------------------------------------------------------------------------
1 | const test = require('tape')
2 | const fs = require('fs')
3 | const leveldown = require('..')
4 | const makeTest = require('./make')
5 |
6 | test('test argument-less repair() throws', function (t) {
7 | t.throws(leveldown.repair, {
8 | name: 'Error',
9 | message: 'repair() requires `location` and `callback` arguments'
10 | }, 'no-arg repair() throws')
11 | t.end()
12 | })
13 |
14 | test('test callback-less, 1-arg, repair() throws', function (t) {
15 | t.throws(leveldown.repair.bind(null, 'foo'), {
16 | name: 'Error',
17 | message: 'repair() requires `location` and `callback` arguments'
18 | }, 'callback-less, 1-arg repair() throws')
19 | t.end()
20 | })
21 |
22 | test('test repair non-existent directory returns error', function (t) {
23 | leveldown.repair('/1/2/3/4', function (err) {
24 | t.ok(/^Error:/i.test(err), 'error on callback')
25 | t.end()
26 | })
27 | })
28 |
29 | // a proxy indicator that RepairDB is being called and doing its thing
30 | makeTest('test repair() compacts', function (db, t, done) {
31 | const location = db.location
32 |
33 | db.close(function (err) {
34 | t.ifError(err, 'no error from close()')
35 |
36 | let files = fs.readdirSync(location)
37 | t.ok(files.some(function (f) { return (/\.log$/).test(f) }), 'directory contains log file(s)')
38 | t.notOk(files.some(function (f) { return (/\.sst$/).test(f) }), 'directory does not contain sst file(s)')
39 |
40 | leveldown.repair(location, function (err) {
41 | t.ifError(err, 'no error from repair()')
42 |
43 | files = fs.readdirSync(location)
44 | t.notOk(files.some(function (f) { return (/\.log$/).test(f) }), 'directory does not contain log file(s)')
45 | t.ok(files.some(function (f) { return (/\.sst$/).test(f) }), 'directory contains sst file(s)')
46 |
47 | done(null, false)
48 | })
49 | })
50 | })
51 |
--------------------------------------------------------------------------------
/test/segfault-test.js:
--------------------------------------------------------------------------------
1 | const test = require('tape')
2 | const testCommon = require('./common')
3 | const operations = []
4 |
5 | // The db must wait for pending operations to finish before closing. This to
6 | // prevent segfaults and in the case of compactRange() to prevent hanging. See
7 | // https://github.com/Level/leveldown/issues/157 and 32.
8 | function testPending (name, expectedCount, fn) {
9 | operations.push(fn)
10 |
11 | test(`close() waits for pending ${name}`, function (t) {
12 | const db = testCommon.factory()
13 | let count = 0
14 |
15 | db.open(function (err) {
16 | t.ifError(err, 'no error from open()')
17 |
18 | db.put('key', 'value', function (err) {
19 | t.ifError(err, 'no error from put()')
20 |
21 | fn(db, function (err) {
22 | count++
23 | t.ifError(err, 'no error from operation')
24 | })
25 |
26 | db.close(function (err) {
27 | t.ifError(err, 'no error from close()')
28 | t.is(count, expectedCount, 'operation(s) finished before close')
29 | t.end()
30 | })
31 | })
32 | })
33 | })
34 | }
35 |
36 | testPending('get()', 1, function (db, next) {
37 | db.get('key', next)
38 | })
39 |
40 | testPending('put()', 1, function (db, next) {
41 | db.put('key2', 'value', next)
42 | })
43 |
44 | testPending('put() with { sync }', 1, function (db, next) {
45 | // The sync option makes the operation slower and thus more likely to
46 | // cause a segfault (if closing were to happen during the operation).
47 | db.put('key2', 'value', { sync: true }, next)
48 | })
49 |
50 | testPending('del()', 1, function (db, next) {
51 | db.del('key', next)
52 | })
53 |
54 | testPending('del() with { sync }', 1, function (db, next) {
55 | db.del('key', { sync: true }, next)
56 | })
57 |
58 | testPending('batch([])', 1, function (db, next) {
59 | db.batch([{ type: 'del', key: 'key' }], next)
60 | })
61 |
62 | testPending('batch([]) with { sync }', 1, function (db, next) {
63 | db.batch([{ type: 'del', key: 'key' }], { sync: true }, next)
64 | })
65 |
66 | testPending('batch()', 1, function (db, next) {
67 | db.batch().del('key').write(next)
68 | })
69 |
70 | testPending('batch() with { sync }', 1, function (db, next) {
71 | db.batch().del('key').write({ sync: true }, next)
72 | })
73 |
74 | testPending('approximateSize()', 1, function (db, next) {
75 | db.approximateSize('a', 'z', next)
76 | })
77 |
78 | testPending('compactRange()', 1, function (db, next) {
79 | db.compactRange('a', 'z', next)
80 | })
81 |
82 | // Test multiple pending operations, using all of the above.
83 | testPending('operations', operations.length, function (db, next) {
84 | for (const fn of operations.slice(0, -1)) {
85 | fn(db, next)
86 | }
87 | })
88 |
89 | // See https://github.com/Level/leveldown/issues/134
90 | test('iterator() does not segfault if db is not open', function (t) {
91 | t.plan(2)
92 |
93 | const db = testCommon.factory()
94 |
95 | try {
96 | db.iterator()
97 | } catch (err) {
98 | t.is(err.message, 'cannot call iterator() before open()')
99 | }
100 |
101 | db.close(function (err) {
102 | t.ifError(err, 'no close error')
103 | })
104 | })
105 |
--------------------------------------------------------------------------------
/test/stack-blower.js:
--------------------------------------------------------------------------------
1 | /**
2 | * This test uses infinite recursion to test iterator creation with limited
3 | * stack space. In order to isolate the test harness, we run in a different
4 | * process. This is achieved through a fork() command in
5 | * iterator-recursion-test.js. To prevent tap from trying to run this test
6 | * directly, we check for a command-line argument.
7 | */
8 | const testCommon = require('./common')
9 |
10 | if (process.argv[2] === 'run') {
11 | const db = testCommon.factory()
12 | let depth = 0
13 |
14 | db.open(function () {
15 | function recurse () {
16 | db.iterator({ gte: '0' })
17 | depth++
18 | recurse()
19 | }
20 |
21 | try {
22 | recurse()
23 | } catch (e) {
24 | process.send('Catchable error at depth ' + depth)
25 | }
26 | })
27 | }
28 |
--------------------------------------------------------------------------------