├── .clang-format ├── .eslintignore ├── .eslintrc.json ├── .github ├── CODEOWNERS ├── dependabot.yml ├── docker │ ├── Dockerfile.glibc │ └── Dockerfile.musl ├── pull_request_template.md └── workflows │ ├── build.yml │ ├── codeql.yml │ ├── lint.yml │ ├── release.yml │ ├── test.yml │ └── webpack.yml ├── .gitignore ├── .mocharc.json ├── .npmignore ├── .prettierrc.json ├── .release-please-manifest.json ├── HISTORY.md ├── LICENSE.md ├── README.md ├── addon ├── compression.cpp ├── compression.h ├── compression_worker.h └── zstd.cpp ├── binding.gyp ├── etc ├── docker.sh └── install-zstd.sh ├── index.d.ts ├── lib └── index.js ├── package-lock.json ├── package.json ├── release-please-config.json ├── sbom.json └── test ├── bundling └── webpack │ ├── .gitignore │ ├── install_zstd.cjs │ ├── package-lock.json │ ├── package.json │ ├── readme.md │ ├── src │ └── index.js │ └── webpack.config.js └── index.test.js /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: Google 2 | AllowShortFunctionsOnASingleLine: Empty 3 | AllowShortIfStatementsOnASingleLine: false 4 | AllowShortLoopsOnASingleLine: false 5 | BinPackArguments: false 6 | BinPackParameters: false 7 | ColumnLimit: 100 8 | Cpp11BracedListStyle: true 9 | DerivePointerAlignment: false 10 | IndentWidth: 4 11 | MaxEmptyLinesToKeep: 1 12 | NamespaceIndentation: None 13 | SpaceBeforeAssignmentOperators: true 14 | Standard: Cpp11 15 | UseTab: Never 16 | InsertNewlineAtEOF: true -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | !.eslintrc.json 2 | !.mocharc.json 3 | !.prettierrc.json 4 | !.release-please-manifest.json -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "extends": [ 4 | "eslint:recommended", 5 | "plugin:prettier/recommended", 6 | "plugin:@typescript-eslint/eslint-recommended", 7 | "plugin:@typescript-eslint/recommended" 8 | ], 9 | "env": { 10 | "node": true, 11 | "mocha": true, 12 | "es6": true 13 | }, 14 | "parserOptions": { 15 | "ecmaVersion": 2019 16 | }, 17 | "plugins": ["@typescript-eslint", "prettier"], 18 | "rules": { 19 | "no-restricted-properties": [ 20 | "error", 21 | { 22 | "object": "describe", 23 | "property": "only" 24 | }, 25 | { 26 | "object": "it", 27 | "property": "only" 28 | }, 29 | { 30 | "object": "context", 31 | "property": "only" 32 | } 33 | ], 34 | "prettier/prettier": "error", 35 | "no-console": "error", 36 | "valid-typeof": "error", 37 | "eqeqeq": [ 38 | "error", 39 | "always", 40 | { 41 | "null": "ignore" 42 | } 43 | ], 44 | "strict": ["error", "global"], 45 | "no-restricted-syntax": [ 46 | "error", 47 | { 48 | "selector": "TSEnumDeclaration", 49 | "message": "Do not declare enums" 50 | }, 51 | { 52 | "selector": "BinaryExpression[operator=/[=!]==/] Identifier[name='undefined']", 53 | "message": "Do not strictly check undefined" 54 | }, 55 | { 56 | "selector": "BinaryExpression[operator=/[=!]==/] Literal[raw='null']", 57 | "message": "Do not strictly check null" 58 | }, 59 | { 60 | "selector": "BinaryExpression[operator=/[=!]==?/] Literal[value='undefined']", 61 | "message": "Do not strictly check typeof undefined (NOTE: currently this rule only detects the usage of 'undefined' string literal so this could be a misfire)" 62 | } 63 | ], 64 | "@typescript-eslint/no-require-imports": "off" 65 | }, 66 | "overrides": [ 67 | { 68 | "files": ["lib/*.js"], 69 | "parserOptions": { 70 | "ecmaVersion": 2019, 71 | "sourceType": "commonjs" 72 | } 73 | }, 74 | { 75 | "files": ["test/**/*ts"], 76 | "rules": { 77 | // chat `expect(..)` style chaining is considered 78 | // an unused expression 79 | "@typescript-eslint/no-unused-expressions": "off" 80 | } 81 | }, 82 | { 83 | // json configuration files 84 | "files": [".*.json"], 85 | "rules": { 86 | "@typescript-eslint/no-unused-expressions": "off" 87 | } 88 | } 89 | ] 90 | } 91 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Everything 2 | * @mongodb-js/dbx-node-devs 3 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "github-actions" # See documentation for possible values 9 | directory: "/" # Location of package manifests 10 | schedule: 11 | interval: "monthly" 12 | - package-ecosystem: "npm" # See documentation for possible values 13 | directory: "/" # Location of package manifests 14 | schedule: 15 | interval: "monthly" 16 | ignore: 17 | # chai is esmodule only. 18 | - dependency-name: "chai" 19 | versions: [">=5.0.0"] 20 | # sinon-chai 4.x+ supports chai 5.x+. 21 | - dependency-name: "sinon-chai" 22 | versions: [">=4.0.0"] 23 | # nyc is Node18+ only starting on nyc@16.x. 24 | - dependency-name: "nyc" 25 | versions: [">=16.0.0"] 26 | # we ignore TS as a part of quarterly dependency updates. 27 | - dependency-name: "typescript" 28 | 29 | # drops support for node 16 30 | - dependency-name: "node-gyp" 31 | versions: [">=11.0.0"] 32 | - dependency-name: "mocha" 33 | versions: [">=11.0.0"] 34 | 35 | allow: 36 | - dependency-type: "development" 37 | 38 | groups: 39 | development-dependencies: 40 | dependency-type: "development" 41 | applies-to: version-updates 42 | update-types: 43 | - "minor" 44 | - "patch" -------------------------------------------------------------------------------- /.github/docker/Dockerfile.glibc: -------------------------------------------------------------------------------- 1 | ARG UBUNTU_VERSION=bionic 2 | FROM ubuntu:${UBUNTU_VERSION} AS build 3 | 4 | ARG NODE_VERSION=16.20.1 5 | # Possible values: s390x, arm64, x64 6 | ARG NODE_ARCH 7 | ADD https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-${NODE_ARCH}.tar.gz / 8 | RUN mkdir -p /nodejs && tar -xzf /node-v${NODE_VERSION}-linux-${NODE_ARCH}.tar.gz --strip-components=1 -C /nodejs 9 | ENV PATH=$PATH:/nodejs/bin 10 | 11 | WORKDIR /zstd 12 | COPY . . 13 | 14 | RUN apt-get -qq update 15 | RUN apt-get -qq install -y python3 build-essential curl cmake 16 | RUN python3 --version 17 | 18 | RUN npm run install-zstd 19 | RUN npm install 20 | RUN npm run prebuild 21 | 22 | ARG RUN_TEST 23 | RUN if [ -n "$RUN_TEST" ]; then npm test ; else echo "skipping tests" ; fi 24 | 25 | FROM scratch 26 | 27 | COPY --from=build /zstd/prebuilds/ / -------------------------------------------------------------------------------- /.github/docker/Dockerfile.musl: -------------------------------------------------------------------------------- 1 | 2 | ARG PLATFORM=arm64 3 | ARG NODE_VERSION=16.20.1 4 | 5 | FROM ${PLATFORM}/node:${NODE_VERSION}-alpine AS build 6 | 7 | WORKDIR /zstd 8 | COPY . . 9 | 10 | RUN apk --no-cache add make g++ libc-dev curl bash python3 py3-pip cmake 11 | RUN npm run install-zstd && npm i 12 | RUN npm run prebuild 13 | 14 | ARG RUN_TEST 15 | RUN if [ -n "$RUN_TEST" ]; then npm test ; else echo "skipping tests" ; fi 16 | 17 | 18 | FROM scratch 19 | 20 | COPY --from=build /zstd/prebuilds/ / 21 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | ### Description 2 | 3 | #### What is changing? 4 | 5 | ##### Is there new documentation needed for these changes? 6 | 7 | #### What is the motivation for this change? 8 | 9 | 10 | 11 | 12 | 18 | 19 | ### Double check the following 20 | 21 | - [ ] Ran `npm run format:js && npm run format:rs` script 22 | - [ ] Self-review completed using the [steps outlined here](https://github.com/mongodb/node-mongodb-native/blob/HEAD/CONTRIBUTING.md#reviewer-guidelines) 23 | - [ ] PR title follows the [correct format](https://www.conventionalcommits.org/en/v1.0.0/): `type(NODE-xxxx)[!]: description` 24 | - Example: `feat(NODE-1234)!: rewriting everything in coffeescript` 25 | - [ ] Changes are covered by tests 26 | - [ ] New TODOs have a related JIRA ticket 27 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | on: 2 | workflow_dispatch: {} 3 | workflow_call: {} 4 | 5 | name: Build 6 | 7 | jobs: 8 | host_tests: 9 | strategy: 10 | matrix: 11 | os: [macos-latest, windows-2019, macos-13] 12 | fail-fast: false 13 | runs-on: ${{ matrix.os }} 14 | steps: 15 | - uses: actions/checkout@v4 16 | 17 | - uses: actions/setup-node@v4 18 | with: 19 | node-version: 16.20.1 20 | cache: "npm" 21 | registry-url: "https://registry.npmjs.org" 22 | 23 | - name: Install zstd 24 | run: npm run install-zstd 25 | shell: bash 26 | 27 | - name: install dependencies and compile 28 | run: npm install --loglevel verbose && npm run prebuild 29 | shell: bash 30 | 31 | - id: upload 32 | name: Upload prebuild 33 | uses: actions/upload-artifact@v4 34 | with: 35 | name: build-${{ matrix.os }} 36 | path: prebuilds/ 37 | if-no-files-found: "error" 38 | retention-days: 1 39 | compression-level: 0 40 | 41 | container_tests_glibc: 42 | runs-on: ubuntu-latest 43 | strategy: 44 | matrix: 45 | linux_arch: [s390x, arm64, amd64] 46 | fail-fast: false 47 | steps: 48 | - uses: actions/checkout@v4 49 | 50 | - uses: actions/setup-node@v4 51 | with: 52 | node-version: ${{ matrix.node }} 53 | 54 | - name: Set up QEMU 55 | uses: docker/setup-qemu-action@v3 56 | 57 | - name: Set up Docker Buildx 58 | uses: docker/setup-buildx-action@v3 59 | 60 | - name: Run Buildx 61 | run: | 62 | docker buildx create --name builder --bootstrap --use 63 | docker buildx build \ 64 | --platform linux/${{ matrix.linux_arch }} \ 65 | --build-arg="NODE_ARCH=${{ matrix.linux_arch == 'amd64' && 'x64' || matrix.linux_arch }}" \ 66 | --build-arg="NODE_VERSION=16.20.1" \ 67 | --output type=local,dest=./prebuilds,platform-split=false \ 68 | -f ./.github/docker/Dockerfile.glibc \ 69 | . 70 | 71 | - id: upload 72 | name: Upload prebuild 73 | uses: actions/upload-artifact@v4 74 | with: 75 | name: build-linux-glibc-${{ matrix.linux_arch }} 76 | path: prebuilds/ 77 | if-no-files-found: "error" 78 | retention-days: 1 79 | compression-level: 0 80 | 81 | container_tests_musl: 82 | runs-on: ubuntu-latest 83 | strategy: 84 | matrix: 85 | linux_arch: [amd64, arm64] 86 | fail-fast: false 87 | steps: 88 | - uses: actions/checkout@v4 89 | 90 | - uses: actions/setup-node@v4 91 | with: 92 | node-version: ${{ matrix.node }} 93 | 94 | - name: Set up QEMU 95 | uses: docker/setup-qemu-action@v3 96 | 97 | - name: Set up Docker Buildx 98 | uses: docker/setup-buildx-action@v3 99 | 100 | - name: Run Buildx 101 | run: | 102 | docker buildx create --name builder --bootstrap --use 103 | docker --debug buildx build --progress=plain --no-cache \ 104 | --platform linux/${{ matrix.linux_arch }} \ 105 | --build-arg="PLATFORM=${{ matrix.linux_arch == 'arm64' && 'arm64v8' || matrix.linux_arch }}" \ 106 | --build-arg="NODE_VERSION=16.20.1" \ 107 | --output type=local,dest=./prebuilds,platform-split=false \ 108 | -f ./.github/docker/Dockerfile.musl \ 109 | . 110 | 111 | - id: upload 112 | name: Upload prebuild 113 | uses: actions/upload-artifact@v4 114 | with: 115 | name: build-linux-musl-${{ matrix.linux_arch }} 116 | path: prebuilds/ 117 | if-no-files-found: "error" 118 | retention-days: 1 119 | compression-level: 0 120 | -------------------------------------------------------------------------------- /.github/workflows/codeql.yml: -------------------------------------------------------------------------------- 1 | name: "CodeQL" 2 | 3 | on: 4 | push: 5 | branches: ["main"] 6 | pull_request: 7 | branches: ["main"] 8 | 9 | jobs: 10 | analyze: 11 | name: Analyze (${{ matrix.language }}) 12 | runs-on: "ubuntu-latest" 13 | timeout-minutes: 360 14 | permissions: 15 | # required for all workflows 16 | security-events: write 17 | 18 | # required to fetch internal or private CodeQL packs 19 | packages: read 20 | 21 | # only required for workflows in private repositories 22 | actions: read 23 | contents: read 24 | 25 | strategy: 26 | fail-fast: false 27 | matrix: 28 | include: 29 | - language: "c-cpp" 30 | build-mode: "manual" 31 | sourceDirectory: "./addon" 32 | - language: "javascript-typescript" 33 | build-mode: "none" 34 | sourceDirectory: "./lib" 35 | steps: 36 | - name: Checkout repository 37 | uses: actions/checkout@v4 38 | 39 | # Initializes the CodeQL tools for scanning. 40 | - name: Initialize CodeQL 41 | uses: github/codeql-action/init@v3 42 | with: 43 | languages: ${{ matrix.language }} 44 | build-mode: ${{ matrix.build-mode }} 45 | source-root: ${{ matrix.sourceDirectory }} 46 | 47 | - if: matrix.build-mode == 'manual' 48 | shell: bash 49 | run: npm i --ignore-scripts && npm run install-zstd && npm run compile 50 | 51 | - name: Perform CodeQL Analysis 52 | uses: github/codeql-action/analyze@v3 53 | with: 54 | category: "/language:${{matrix.language}}" 55 | -------------------------------------------------------------------------------- /.github/workflows/lint.yml: -------------------------------------------------------------------------------- 1 | name: Lint 2 | 3 | on: 4 | push: 5 | branches: [ "main" ] 6 | pull_request: 7 | branches: [ "main" ] 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | 13 | name: ${{ matrix.lint-target }} 14 | strategy: 15 | matrix: 16 | lint-target: ["c++", "typescript"] 17 | 18 | steps: 19 | - uses: actions/checkout@v4 20 | 21 | - name: Use Node.js LTS 22 | uses: actions/setup-node@v4 23 | with: 24 | node-version: 'lts/*' 25 | cache: 'npm' 26 | 27 | - name: Install dependencies 28 | shell: bash 29 | run: npm i --ignore-scripts 30 | 31 | - if: matrix.lint-target == 'c++' 32 | shell: bash 33 | run: | 34 | npm run check:clang-format 35 | - if: matrix.lint-target == 'typescript' 36 | shell: bash 37 | run: | 38 | npm run check:eslint -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: ["main"] 4 | workflow_dispatch: {} 5 | 6 | permissions: 7 | contents: write 8 | pull-requests: write 9 | id-token: write 10 | 11 | name: release 12 | 13 | jobs: 14 | release_please: 15 | runs-on: ubuntu-latest 16 | outputs: 17 | release_created: ${{ steps.release.outputs.release_created }} 18 | steps: 19 | - id: release 20 | uses: googleapis/release-please-action@v4 21 | with: 22 | target-branch: main 23 | 24 | build: 25 | needs: [release_please] 26 | name: "Perform any build or bundling steps, as necessary." 27 | uses: ./.github/workflows/build.yml 28 | 29 | ssdlc: 30 | needs: [release_please, build] 31 | permissions: 32 | # required for all workflows 33 | security-events: write 34 | id-token: write 35 | contents: write 36 | environment: release 37 | runs-on: ubuntu-latest 38 | steps: 39 | - uses: actions/checkout@v4 40 | 41 | - name: Install Node and dependencies 42 | uses: mongodb-labs/drivers-github-tools/node/setup@v2 43 | with: 44 | ignore_install_scripts: true 45 | 46 | - name: Load version and package info 47 | uses: mongodb-labs/drivers-github-tools/node/get_version_info@v2 48 | with: 49 | npm_package_name: "@mongodb-js/zstd" 50 | 51 | - name: actions/compress_sign_and_upload 52 | uses: mongodb-labs/drivers-github-tools/node/sign_node_package@v2 53 | with: 54 | aws_role_arn: ${{ secrets.AWS_ROLE_ARN }} 55 | aws_region_name: us-east-1 56 | aws_secret_id: ${{ secrets.AWS_SECRET_ID }} 57 | npm_package_name: "@mongodb-js/zstd" 58 | dry_run: ${{ needs.release_please.outputs.release_created == '' }} 59 | sign_native: true 60 | 61 | - name: Copy sbom file to release assets 62 | shell: bash 63 | if: ${{ 'node-zstd' == '' }} 64 | run: cp sbom.json ${{ env.S3_ASSETS }}/sbom.json 65 | 66 | - name: Augment SBOM and copy to release assets 67 | if: ${{ 'node-zstd' != '' }} 68 | uses: mongodb-labs/drivers-github-tools/sbom@v2 69 | with: 70 | silk_asset_group: "node-zstd" 71 | sbom_file_name: sbom.json 72 | 73 | - name: Generate authorized pub report 74 | uses: mongodb-labs/drivers-github-tools/full-report@v2 75 | with: 76 | release_version: ${{ env.package_version }} 77 | product_name: "@mongodb-js/zstd" 78 | sarif_report_target_ref: main 79 | third_party_dependency_tool: n/a 80 | dist_filenames: artifacts/* 81 | token: ${{ github.token }} 82 | sbom_file_name: sbom.json 83 | 84 | - uses: mongodb-labs/drivers-github-tools/upload-s3-assets@v2 85 | with: 86 | version: ${{ env.package_version }} 87 | product_name: "@mongodb-js/zstd" 88 | dry_run: ${{ needs.release_please.outputs.release_created == '' }} 89 | 90 | publish: 91 | needs: [release_please, ssdlc, build] 92 | environment: release 93 | runs-on: ubuntu-latest 94 | steps: 95 | - uses: actions/checkout@v4 96 | 97 | - name: Install Node and dependencies 98 | uses: mongodb-labs/drivers-github-tools/node/setup@v2 99 | with: 100 | ignore_install_scripts: true 101 | 102 | - run: npm publish --provenance 103 | if: ${{ needs.release_please.outputs.release_created }} 104 | env: 105 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 106 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: [main] 4 | pull_request: 5 | branches: [main] 6 | workflow_dispatch: {} 7 | 8 | name: Test 9 | 10 | jobs: 11 | host_tests: 12 | strategy: 13 | matrix: 14 | os: [macos-latest, windows-2019, macos-13] 15 | node: [16.20.1, 18.x, 20.x, 22.x] 16 | fail-fast: false 17 | runs-on: ${{ matrix.os }} 18 | steps: 19 | - uses: actions/checkout@v4 20 | 21 | - uses: actions/setup-node@v4 22 | with: 23 | node-version: ${{ matrix.node }} 24 | cache: "npm" 25 | registry-url: "https://registry.npmjs.org" 26 | 27 | - name: Install zstd 28 | run: npm run install-zstd 29 | shell: bash 30 | 31 | - name: install dependencies and compile 32 | run: npm install --ignore-scripts --loglevel verbose && npm run prebuild 33 | shell: bash 34 | 35 | - name: Test ${{ matrix.os }} 36 | shell: bash 37 | run: npm test 38 | 39 | container_tests_glibc: 40 | runs-on: ubuntu-latest 41 | strategy: 42 | matrix: 43 | linux_arch: [s390x, arm64, amd64] 44 | node: [16.x, 18.x, 20.x, 22.x] 45 | fail-fast: false 46 | steps: 47 | - uses: actions/checkout@v4 48 | 49 | - uses: actions/setup-node@v4 50 | with: 51 | node-version: ${{ matrix.node }} 52 | 53 | - name: Get Full Node.js Version 54 | id: get_nodejs_version 55 | shell: bash 56 | run: | 57 | echo "version=$(node --print 'process.version.slice(1)')" >> "$GITHUB_OUTPUT" 58 | echo "ubuntu_version=$(node --print '(+process.version.slice(1).split(`.`).at(0)) > 16 ? `noble` : `bionic`')" >> "$GITHUB_OUTPUT" 59 | 60 | - name: Set up QEMU 61 | uses: docker/setup-qemu-action@v3 62 | 63 | - name: Set up Docker Buildx 64 | uses: docker/setup-buildx-action@v3 65 | 66 | - name: Run Buildx 67 | run: | 68 | docker buildx create --name builder --bootstrap --use 69 | docker buildx build \ 70 | --platform linux/${{ matrix.linux_arch }} \ 71 | --build-arg="NODE_ARCH=${{ matrix.linux_arch == 'amd64' && 'x64' || matrix.linux_arch }}" \ 72 | --build-arg="NODE_VERSION=${{ steps.get_nodejs_version.outputs.version }}" \ 73 | --build-arg="UBUNTU_VERSION=${{ steps.get_nodejs_version.outputs.ubuntu_version }}" \ 74 | --build-arg="RUN_TEST=true" \ 75 | --output type=local,dest=./prebuilds,platform-split=false \ 76 | -f ./.github/docker/Dockerfile.glibc \ 77 | . 78 | 79 | container_tests_musl: 80 | runs-on: ubuntu-latest 81 | strategy: 82 | matrix: 83 | linux_arch: [amd64, arm64] 84 | node: [16.20.1, 18.x, 20.x, 22.x] 85 | fail-fast: false 86 | steps: 87 | - uses: actions/checkout@v4 88 | 89 | - uses: actions/setup-node@v4 90 | with: 91 | node-version: ${{ matrix.node }} 92 | 93 | - name: Get Full Node.js Version 94 | id: get_nodejs_version 95 | shell: bash 96 | run: | 97 | echo "version=$(node --print 'process.version.slice(1)')" >> "$GITHUB_OUTPUT" 98 | 99 | - name: Set up QEMU 100 | uses: docker/setup-qemu-action@v3 101 | 102 | - name: Set up Docker Buildx 103 | uses: docker/setup-buildx-action@v3 104 | 105 | - name: Run Buildx 106 | run: | 107 | docker buildx create --name builder --bootstrap --use 108 | docker --debug buildx build --progress=plain --no-cache \ 109 | --platform linux/${{ matrix.linux_arch }} \ 110 | --build-arg="PLATFORM=${{ matrix.linux_arch == 'arm64' && 'arm64v8' || matrix.linux_arch }}" \ 111 | --build-arg="NODE_VERSION=${{ steps.get_nodejs_version.outputs.version }}" \ 112 | --build-arg="RUN_TEST=true" \ 113 | --output type=local,dest=./prebuilds,platform-split=false \ 114 | -f ./.github/docker/Dockerfile.musl \ 115 | . 116 | -------------------------------------------------------------------------------- /.github/workflows/webpack.yml: -------------------------------------------------------------------------------- 1 | name: Webpack 2 | 3 | on: 4 | push: 5 | branches: [ "main" ] 6 | pull_request: 7 | branches: [ "main" ] 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - uses: actions/checkout@v4 15 | 16 | - name: Use Node.js LTS 17 | uses: actions/setup-node@v4 18 | with: 19 | node-version: 'lts/*' 20 | 21 | - name: "Install dependencies" 22 | shell: bash 23 | run: | 24 | npm install 25 | 26 | - name: "Install dependencies in the Webpack bundle test package" 27 | shell: bash 28 | working-directory: ./test/bundling/webpack 29 | run: | 30 | npm install 31 | 32 | - name: "Install local zstd into Webpack bundle test package" 33 | shell: bash 34 | working-directory: ./test/bundling/webpack 35 | run: | 36 | npm run install:zstd 37 | 38 | - name: "Run webpack build" 39 | shell: bash 40 | working-directory: ./test/bundling/webpack 41 | run: | 42 | npm run build -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | lib-cov 2 | *.seed 3 | *.log 4 | *.csv 5 | *.dat 6 | *.out 7 | *.pid 8 | *.gz 9 | *.node 10 | .DS_Store 11 | 12 | .vscode 13 | xunit.xml 14 | pids 15 | logs 16 | results 17 | node_modules 18 | build 19 | 20 | npm-debug.log 21 | deps 22 | 23 | prebuilds -------------------------------------------------------------------------------- /.mocharc.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/mocharc.json", 3 | "extension": ["ts"], 4 | "recursive": true, 5 | "failZero": true, 6 | "color": true, 7 | "timeout": 0 8 | } 9 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .github 2 | npm 3 | .eslintrc 4 | .prettierignore 5 | rustfmt.toml 6 | yarn.lock 7 | *.node 8 | -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "tabWidth": 2, 4 | "printWidth": 100, 5 | "arrowParens": "avoid", 6 | "trailingComma": "none" 7 | } 8 | -------------------------------------------------------------------------------- /.release-please-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | ".": "2.0.1" 3 | } 4 | -------------------------------------------------------------------------------- /HISTORY.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. 4 | 5 | ## [2.0.1](https://github.com/mongodb-js/zstd/compare/v2.0.0...v2.0.1) (2025-02-10) 6 | 7 | 8 | ### Bug Fixes 9 | 10 | * **NODE-6731:** fix and test webpack bundling ([#71](https://github.com/mongodb-js/zstd/issues/71)) ([94449cf](https://github.com/mongodb-js/zstd/commit/94449cfb0ab71eb0fd2c8b4ee89a2af7c8a95cbb)) 11 | 12 | ## [2.0.0](https://github.com/mongodb-js/zstd/compare/v2.0.0-alpha.3...v2.0.0) (2024-12-06) 13 | 14 | 15 | ### Miscellaneous Chores 16 | 17 | * release 2.0.0 (Release-As: 2.0.0) ([#60](https://github.com/mongodb-js/zstd/issues/60)) ([7e1d253](https://github.com/mongodb-js/zstd/commit/7e1d253c601ad14ad34f1dc75f45f1af2d177891)) 18 | 19 | ## [2.0.0-alpha.3](https://github.com/mongodb-js/zstd/compare/v2.0.0-alpha.2...v2.0.0-alpha.3) (2024-12-05) 20 | 21 | ### Bug Fixes 22 | 23 | * bundle release build on windows ([#59](https://github.com/mongodb-js/zstd/issues/59)) ([999c506](https://github.com/mongodb-js/zstd/commit/999c5064f7e1033a889b4e1d9b3cd491a5ec2ff9)) 24 | 25 | ## [2.0.0-alpha.2](https://github.com/mongodb-js/zstd/compare/v2.0.0-alpha.1...v2.0.0-alpha.2) (2024-12-04) 26 | 27 | 28 | ### Bug Fixes 29 | 30 | * **NODE-6590:** add build for x64 macos ([#45](https://github.com/mongodb-js/zstd/issues/45)) ([4972129](https://github.com/mongodb-js/zstd/commit/4972129c5e1a48d4f448324e597df9c2a8f91f25)) 31 | 32 | ## [2.0.0-alpha.1](https://github.com/mongodb-js/zstd/compare/v2.0.0-alpha.0...v2.0.0-alpha.1) (2024-12-02) 33 | 34 | 35 | ### Bug Fixes 36 | 37 | * **NODE-6590:** specify correct entrypoint in package.json and include binding.gyp in the package ([#47](https://github.com/mongodb-js/zstd/issues/47)) ([f562b59](https://github.com/mongodb-js/zstd/commit/f562b59dea298ebf22a54106d71d3cf61b7fa8df)) 38 | 39 | ## [v2.0.0-alpha.0](https://github.com/mongodb-js/zstd/compare/v1.2.2...v2.0.0-alpha.0) (2024-11-27) 40 | 41 | ### Features 42 | 43 | * **NODE-4569:** add "musl" builds for Alpine Linux ([#12](https://github.com/mongodb-js/zstd/issues/12)) ([b3dedc3](https://github.com/mongodb-js/zstd/commit/b3dedc31a274df1eecb54b9092c8dd270f31c21c)) 44 | * **NODE-6539:** add base napi C++ template with standard Node team tooling ([#28](https://github.com/mongodb-js/zstd/issues/28)) ([8c40b08](https://github.com/mongodb-js/zstd/commit/8c40b08782969c87b85d5d1bea0a753db73cc87f)) 45 | * **NODE-6540:** Add c++ zstd compression API ([#30](https://github.com/mongodb-js/zstd/issues/30)) ([6673245](https://github.com/mongodb-js/zstd/commit/667324522600abc6f731b54a9d9a7c6e92954bef)) 46 | * **NODE-6588:** add ssdlc to zstd ([#43](https://github.com/mongodb-js/zstd/issues/43)) ([016d857](https://github.com/mongodb-js/zstd/commit/016d857ccb76f01ebaf18e01756b571338723a16)) 47 | 48 | ### [1.2.2](https://github.com/mongodb-js/zstd/compare/v1.2.1...v1.2.2) (2024-09-16) 49 | 50 | 51 | ### Bug Fixes 52 | 53 | * **NODE-6381:** use targeting for x86_64 darwin ([#26](https://github.com/mongodb-js/zstd/issues/26)) ([f95c9f6](https://github.com/mongodb-js/zstd/commit/f95c9f6b1e836cce7da4e6955181261110e88487)) 54 | 55 | ### [1.2.1](https://github.com/mongodb-js/zstd/compare/v1.2.0...v1.2.1) (2024-09-06) 56 | 57 | 58 | ### Bug Fixes 59 | 60 | * **NODE-6348:** Wrap thrown errors in JS Error objects with stacks ([#25](https://github.com/mongodb-js/zstd/issues/25)) ([af62c4f](https://github.com/mongodb-js/zstd/commit/af62c4f5f816386ce605c20641ad30cc74bb77e2)) 61 | 62 | ## [1.2.0](https://github.com/mongodb-js/zstd/compare/v1.1.0...v1.2.0) (2023-08-29) 63 | 64 | 65 | ### Bug Fixes 66 | 67 | * **NODE-5177:** update to latest zstd-sys ([#15](https://github.com/mongodb-js/zstd/issues/15)) ([6b6d8ce](https://github.com/mongodb-js/zstd/commit/6b6d8ce098de757c53fd52a09d47aa3e29ed2902)) 68 | 69 | ## [1.1.0](https://github.com/mongodb-js/zstd/compare/v1.0.0...v1.1.0) (2023-01-23) 70 | 71 | 72 | ### Features 73 | 74 | * **NODE-4569:** add "musl" builds for Alpine Linux ([#12](https://github.com/mongodb-js/zstd/issues/12)) ([b3dedc3](https://github.com/mongodb-js/zstd/commit/b3dedc31a274df1eecb54b9092c8dd270f31c21c)) 75 | 76 | ## [1.0.0](https://github.com/mongodb-js/zstd/compare/v0.0.7...v1.0.0) (2022-05-18) 77 | 78 | ### [0.0.7](https://github.com/mongodb-js/zstd/compare/v0.0.6...v0.0.7) (2022-05-18) 79 | 80 | 81 | ### Bug Fixes 82 | 83 | * fix macos arm64 build ([#9](https://github.com/mongodb-js/zstd/issues/9)) ([1ebefde](https://github.com/mongodb-js/zstd/commit/1ebefdedb761b34bcc721a934296d3ac9f0e7a1b)) 84 | 85 | ### [0.0.6](https://github.com/mongodb-js/zstd/compare/v0.0.5...v0.0.6) (2022-05-18) 86 | 87 | 88 | ### Features 89 | 90 | * add readme ([833aa92](https://github.com/mongodb-js/zstd/commit/833aa92213236ef35c4bd79d4c462751a3b4e634)) 91 | * update readme ([49ac44e](https://github.com/mongodb-js/zstd/commit/49ac44efbe9a4ab544958b97ae178b51cac057ff)) 92 | 93 | ### [0.0.5](https://github.com/mongodb-js/zstd/compare/v0.0.4...v0.0.5) (2022-05-09) 94 | 95 | 96 | ### Bug Fixes 97 | 98 | * remove 686 win build ([ea36ddc](https://github.com/mongodb-js/zstd/commit/ea36ddc0ce3e6630321e7074a138f2d45dd16f4f)) 99 | 100 | ### [0.0.4](https://github.com/mongodb-js/zstd/compare/v0.0.3...v0.0.4) (2022-05-06) 101 | 102 | 103 | ### Features 104 | 105 | * **NODE-1837:** support passing compression level ([2c1a917](https://github.com/mongodb-js/zstd/commit/2c1a9171c689c1fc87428d383ffeb823291f84cf)) 106 | 107 | ### [0.0.3](https://github.com/mongodb-js/zstd/compare/v0.0.2...v0.0.3) (2022-05-06) 108 | 109 | 110 | ### Bug Fixes 111 | 112 | * update publish task regex ([b62d9b0](https://github.com/mongodb-js/zstd/commit/b62d9b0e644c85d3443f738d953ae7816d3eba00)) 113 | 114 | ### [0.0.2](https://github.com/mongodb-js/zstd/compare/v0.0.1...v0.0.2) (2022-05-06) 115 | 116 | 117 | ### Bug Fixes 118 | 119 | * dont use org in napi name ([9063ea8](https://github.com/mongodb-js/zstd/commit/9063ea8bb7b187aacd876f75b3e74bc0188e7a2b)) 120 | 121 | ### 0.0.1 (2022-05-05) 122 | 123 | 124 | ### Features 125 | 126 | * add release script ([c2c1783](https://github.com/mongodb-js/zstd/commit/c2c1783242766c8b65f57838494d1a3c4dc23305)) 127 | * add standard version ([f63a9b9](https://github.com/mongodb-js/zstd/commit/f63a9b95ba261004cb2f481ff201fa2e116d3aed)) 128 | * initial project setup ([53671a3](https://github.com/mongodb-js/zstd/commit/53671a393326605650d3ae12959796a6c6976472)) 129 | * update package.json files ([7823f1b](https://github.com/mongodb-js/zstd/commit/7823f1b3156f4eacd2c235ac660aa9810eee6f84)) 130 | * update to idomatic rust ([16e215a](https://github.com/mongodb-js/zstd/commit/16e215a59817fdf94bb62c8620b49b6255bafda0)) 131 | 132 | 133 | ### Bug Fixes 134 | 135 | * handle status in error ([e29c0ed](https://github.com/mongodb-js/zstd/commit/e29c0ed3b1077987c28bc4daa11c5d6a01c650cf)) 136 | * remove debug js ([c454785](https://github.com/mongodb-js/zstd/commit/c454785a6cbfe63ed21ca3942ce0707e0b399d3f)) 137 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2022 MongoDB 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # @mongodb-js/zstd 2 | 3 | [![CI](https://github.com/mongodb-js/zstd/actions/workflows/test.yml/badge.svg)](https://github.com/mongodb-js/zstd/actions/workflows/test.yml) 4 | 5 | Zstandard compression library for Node.js 6 | 7 | ## Installation 8 | 9 | ``` 10 | npm install @mongodb-js/zstd 11 | ``` 12 | 13 | ### Release Integrity 14 | 15 | Releases are created automatically and signed using the [Node team's GPG key](https://pgp.mongodb.com/node-driver.asc). This applies to the git tag as well as all release packages provided as part of a GitHub release. To verify the provided packages, download the key and import it using gpg: 16 | 17 | ``` 18 | gpg --import node-driver.asc 19 | ``` 20 | 21 | The GitHub release contains a detached signature file for the NPM package (named 22 | `mongodb-js-zstd-X.Y.Z.tgz.sig`). 23 | 24 | The following command returns the link npm package. 25 | ```shell 26 | npm view @mongodb-js/zstd@vX.Y.Z dist.tarball 27 | ``` 28 | 29 | Using the result of the above command, a `curl` command can return the official npm package for the release. 30 | 31 | To verify the integrity of the downloaded package, run the following command: 32 | ```shell 33 | gpg --verify mongodb-js-zstd-X.Y.Z.tgz.sig mongodb-js-zstd-X.Y.Z.tgz 34 | ``` 35 | 36 | >[!Note] 37 | No verification is done when using npm to install the package. The contents of the Github tarball and npm's tarball are identical. 38 | 39 | To verify the native `.node` packages, follow the same steps as above using `mongodb-js-zstd-X.Y.Z-platform.tgz` and the corresponding `.sig` file. 40 | 41 | ## MongoDB Node.js Driver Version Compatibility 42 | 43 | Only the following version combinations with the [MongoDB Node.js Driver](https://github.com/mongodb/node-mongodb-native) are considered stable. 44 | 45 | | | `@mongodb-js/zstd@1.x` | `@mongodb-js/zstd@2.x` | 46 | | ---------------- | ---------------------- | ---------------------- | 47 | | `mongodb@>=6.12` | ✓ `^1.1.0` | `^2.0.0` | 48 | | `mongodb@<6.12` | ✓ `^1.1.0` | N/A | 49 | | `mongodb@5.x` | ✓ | N/A | 50 | | `mongodb@4.x` | ✓ | N/A | 51 | | `mongodb@3.x` | N/A | N/A | 52 | 53 | >[!Note] 54 | > `@mongodb-js/zstd@1.x` is deprecated - please use `@mongodb-js/zstd@2.x` instead. 55 | 56 | #### Prebuild Platforms 57 | 58 | Below are the platforms that are available as prebuilds on each github release. 59 | `prebuild-install` downloads these automatically depending on the platform you are running npm install on. 60 | 61 | - Linux GLIBC 2.23 or later 62 | - s390x 63 | - arm64 64 | - x64 65 | - Linux MUSL 1.1.20 66 | - arm64 67 | - x64 68 | - MacOS universal binary 69 | - x64 70 | - arm64 71 | - Windows 72 | - x64 73 | 74 | ## API 75 | 76 | ```ts 77 | export function compress(buffer: Buffer | ArrayBuffer | Uint8Array, level: number): Promise; 78 | export function decompress(buffer: Buffer): Promise; 79 | ``` 80 | 81 | ### Bugs / Feature Requests 82 | 83 | Think you’ve found a bug? Want to see a new feature in `@mongodb-js/zstd`? Please open a 84 | case in our issue management tool, JIRA: 85 | 86 | - Create an account and login [jira.mongodb.org](https://jira.mongodb.org). 87 | - Navigate to the NODE project [jira.mongodb.org/browse/NODE](https://jira.mongodb.org/browse/NODE). 88 | - Click **Create Issue** - Please provide as much information as possible about the issue type and how to reproduce it. 89 | 90 | ### Support / Feedback 91 | 92 | For issues with, questions about, or feedback for the library, please look into our [support channels](https://docs.mongodb.com/manual/support). Please do not email any of the driver developers directly with issues or questions - you're more likely to get an answer on the [MongoDB Community Forums](https://community.mongodb.com/tags/c/drivers-odms-connectors/7/node-js-driver). 93 | 94 | ### Change Log 95 | 96 | Change history can be found in [`HISTORY.md`](https://github.com/mongodb-js/zstd/blob/HEAD/HISTORY.md). 97 | 98 | ## Usage 99 | 100 | ```ts 101 | import { compress, decompress } from '@mongodb-js/zstd'; 102 | 103 | (async () => { 104 | const buffer = Buffer.from('test'); 105 | const compressed = await compress(buffer, 10); 106 | const decompressed = await decompress(compressed); 107 | })(); 108 | ``` 109 | 110 | ## Running Tests 111 | 112 | First, install and build the zstd library: 113 | 114 | `npm run install-zstd` 115 | 116 | Then build the bindings: 117 | 118 | `npm run prebuild` 119 | 120 | Then test: 121 | `npm test` 122 | -------------------------------------------------------------------------------- /addon/compression.cpp: -------------------------------------------------------------------------------- 1 | #include "compression.h" 2 | 3 | std::vector mongodb_zstd::compress(const std::vector& data, 4 | size_t compression_level) { 5 | size_t output_buffer_size = ZSTD_compressBound(data.size()); 6 | std::vector output(output_buffer_size); 7 | 8 | size_t result_code = 9 | ZSTD_compress(output.data(), output.size(), data.data(), data.size(), compression_level); 10 | 11 | if (ZSTD_isError(result_code)) { 12 | throw std::runtime_error(ZSTD_getErrorName(result_code)); 13 | } 14 | 15 | output.resize(result_code); 16 | 17 | return output; 18 | } 19 | 20 | std::vector mongodb_zstd::decompress(const std::vector& compressed) { 21 | std::vector decompressed; 22 | 23 | using DCTX_Deleter = void (*)(ZSTD_DCtx*); 24 | 25 | std::unique_ptr decompression_context( 26 | ZSTD_createDCtx(), [](ZSTD_DCtx* ctx) { ZSTD_freeDCtx(ctx); }); 27 | 28 | ZSTD_inBuffer input = {compressed.data(), compressed.size(), 0}; 29 | std::vector output_buffer(ZSTD_DStreamOutSize()); 30 | ZSTD_outBuffer output = {output_buffer.data(), output_buffer.size(), 0}; 31 | 32 | // Source: https://facebook.github.io/zstd/zstd_manual.html#Chapter9 33 | // 34 | // Use ZSTD_decompressStream() repetitively to consume your input. 35 | // The function will update both `pos` fields. 36 | // If `input.pos < input.size`, some input has not been consumed. 37 | // It's up to the caller to present again remaining data. 38 | // The function tries to flush all data decoded immediately, respecting output buffer size. 39 | // If `output.pos < output.size`, decoder has flushed everything it could. 40 | // But if `output.pos == output.size`, there might be some data left within internal buffers., 41 | // In which case, call ZSTD_decompressStream() again to flush whatever remains in the buffer. 42 | // Note : with no additional input provided, amount of data flushed is necessarily <= 43 | // ZSTD_BLOCKSIZE_MAX. 44 | // @return : 0 when a frame is completely decoded and fully flushed, 45 | // or an error code, which can be tested using ZSTD_isError(), 46 | // or any other value > 0, which means there is still some decoding or flushing to do to 47 | // complete current frame : 48 | // the return value is a suggested next input size (just a hint 49 | // for better latency) that will never request more than the 50 | // remaining frame size. 51 | auto inputRemains = [](const ZSTD_inBuffer& input) { return input.pos < input.size; }; 52 | auto isOutputBufferFlushed = [](const ZSTD_outBuffer& output) { 53 | return output.pos < output.size; 54 | }; 55 | 56 | while (inputRemains(input) || !isOutputBufferFlushed(output)) { 57 | size_t const ret = ZSTD_decompressStream(decompression_context.get(), &output, &input); 58 | if (ZSTD_isError(ret)) { 59 | throw std::runtime_error(ZSTD_getErrorName(ret)); 60 | } 61 | 62 | size_t decompressed_size = decompressed.size(); 63 | decompressed.resize(decompressed_size + output.pos); 64 | std::copy(output_buffer.data(), 65 | output_buffer.data() + output.pos, 66 | decompressed.data() + decompressed_size); 67 | 68 | // move the position back go 0, to indicate that we are ready for more data 69 | output.pos = 0; 70 | } 71 | 72 | return decompressed; 73 | } 74 | -------------------------------------------------------------------------------- /addon/compression.h: -------------------------------------------------------------------------------- 1 | #ifndef MONGODB_ZSTD_COMPRESSION 2 | #define MONGODB_ZSTD_COMPRESSION 3 | 4 | #include 5 | #include 6 | 7 | #include "compression_worker.h" 8 | #include "zstd.h" 9 | 10 | namespace mongodb_zstd { 11 | std::vector compress(const std::vector& data, size_t compression_level); 12 | std::vector decompress(const std::vector& data); 13 | } // namespace mongodb_zstd 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /addon/compression_worker.h: -------------------------------------------------------------------------------- 1 | #ifndef MONGODB_ZSTD_COMPRESSION_WORKER_H 2 | #define MONGODB_ZSTD_COMPRESSION_WORKER_H 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | using namespace Napi; 9 | 10 | namespace mongodb_zstd { 11 | /** 12 | * @brief An asynchronous Napi::Worker that can be with any function that produces 13 | * CompressionResults. 14 | * */ 15 | class CompressionWorker final : public AsyncWorker { 16 | public: 17 | CompressionWorker(const Function& callback, std::function()> worker) 18 | : AsyncWorker{callback, "compression worker"}, m_worker(worker), m_result{} {} 19 | 20 | protected: 21 | void Execute() final { 22 | m_result = m_worker(); 23 | } 24 | 25 | void OnOK() final { 26 | if (!m_result.has_value()) { 27 | Callback().Call({Error::New(Env(), 28 | "zstd runtime - async worker finished without " 29 | "a compression or decompression result.") 30 | .Value()}); 31 | return; 32 | } 33 | 34 | const std::vector& data = m_result.value(); 35 | Buffer result = Buffer::Copy(Env(), data.data(), data.size()); 36 | 37 | Callback().Call({Env().Undefined(), result}); 38 | } 39 | 40 | private: 41 | std::function()> m_worker; 42 | std::optional> m_result; 43 | }; 44 | 45 | } // namespace mongodb_zstd 46 | #endif 47 | -------------------------------------------------------------------------------- /addon/zstd.cpp: -------------------------------------------------------------------------------- 1 | #include "zstd.h" 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include "compression.h" 8 | #include "compression_worker.h" 9 | 10 | using namespace Napi; 11 | 12 | namespace mongodb_zstd { 13 | void Compress(const CallbackInfo& info) { 14 | // Argument handling happens in JS 15 | if (info.Length() != 3) { 16 | const char* error_message = "Expected three arguments."; 17 | throw TypeError::New(info.Env(), error_message); 18 | } 19 | 20 | Uint8Array to_compress = info[0].As(); 21 | std::vector data(to_compress.Data(), to_compress.Data() + to_compress.ElementLength()); 22 | 23 | size_t compression_level = static_cast(info[1].ToNumber().Int32Value()); 24 | Function callback = info[2].As(); 25 | 26 | CompressionWorker* worker = 27 | new CompressionWorker(callback, [data = std::move(data), compression_level] { 28 | return mongodb_zstd::compress(data, compression_level); 29 | }); 30 | 31 | worker->Queue(); 32 | } 33 | 34 | void Decompress(const CallbackInfo& info) { 35 | // Argument handling happens in JS 36 | if (info.Length() != 2) { 37 | const char* error_message = "Expected two argument."; 38 | throw TypeError::New(info.Env(), error_message); 39 | } 40 | 41 | Uint8Array compressed_data = info[0].As(); 42 | std::vector data(compressed_data.Data(), 43 | compressed_data.Data() + compressed_data.ElementLength()); 44 | Function callback = info[1].As(); 45 | 46 | CompressionWorker* worker = new CompressionWorker( 47 | callback, [data = std::move(data)] { return mongodb_zstd::decompress(data); }); 48 | 49 | worker->Queue(); 50 | } 51 | 52 | Object Init(Env env, Object exports) { 53 | exports.Set(String::New(env, "compress"), Function::New(env, Compress)); 54 | exports.Set(String::New(env, "decompress"), Function::New(env, Decompress)); 55 | return exports; 56 | } 57 | 58 | NODE_API_MODULE(zstd, Init) 59 | 60 | } // namespace mongodb_zstd 61 | -------------------------------------------------------------------------------- /binding.gyp: -------------------------------------------------------------------------------- 1 | { 2 | 'targets': [{ 3 | 'target_name': 'zstd', 4 | 'type': 'loadable_module', 5 | 'defines': ['ZSTD_STATIC_LINKING_ONLY'], 6 | 'include_dirs': [ 7 | " 16 ? `noble` : `bionic`' $NODE_VERSION) 32 | NODE_ARCH=$(node -p 'process.argv[1] === `amd64` && `x64` || process.argv[1]' $LINUX_ARCH) 33 | echo $UBUNTU_VERSION 34 | docker buildx build --progress=plain --no-cache \ 35 | --platform linux/$LINUX_ARCH \ 36 | --build-arg="NODE_ARCH=$NODE_ARCH" \ 37 | --build-arg="NODE_VERSION=$NODE_VERSION" \ 38 | --build-arg="UBUNTU_VERSION$UBUNTU_VERSION" \ 39 | --build-arg="RUN_TEST=true" \ 40 | --output type=local,dest=./prebuilds,platform-split=false \ 41 | -f ./.github/docker/Dockerfile.glibc \ 42 | $PROJECT_DIR 43 | } 44 | 45 | 46 | build_and_test_musl -------------------------------------------------------------------------------- /etc/install-zstd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -o xtrace 3 | set -o errexit 4 | 5 | clean_deps() { 6 | rm -rf deps 7 | } 8 | 9 | download_zstd() { 10 | mkdir -p deps/zstd 11 | ZSTD_VERSION=$(node -p "require('./package.json')['mongodb:zstd_version']") 12 | 13 | # only unpack the source and build files needed to compile the project 14 | necessary_files="zstd-$ZSTD_VERSION/build zstd-$ZSTD_VERSION/lib zstd-$ZSTD_VERSION/programs" 15 | 16 | # flags 17 | # -L follow redirects 18 | # -C output directory 19 | # - tar from stdin 20 | # --strip-components ignore the top-level directory when unpacking 21 | curl -L "https://github.com/facebook/zstd/releases/download/v$ZSTD_VERSION/zstd-$ZSTD_VERSION.tar.gz" \ 22 | | tar -zxf - -C deps/zstd --strip-components 1 $necessary_files 23 | } 24 | 25 | build_zstd() { 26 | export MACOSX_DEPLOYMENT_TARGET=11 27 | cd deps/zstd 28 | 29 | mkdir out 30 | cd out 31 | 32 | # CMAKE_RC_FLAGS is a workaround for a bug in 1.5.6 that breaks compilation on windows. 33 | # The fix is merged but not yet released. see https://github.com/facebook/zstd/issues/3999 34 | cmake \ 35 | -DCMAKE_RC_FLAGS="$(pwd)/lib" \ 36 | -DZSTD_MULTITHREAD_SUPPORT=OFF \ 37 | -DZSTD_BUILD_SHARED=OFF \ 38 | -DCMAKE_OSX_ARCHITECTURES='x86_64;arm64' \ 39 | -DCMAKE_BUILD_TYPE=Release \ 40 | ../build/cmake 41 | 42 | cmake --build . --target libzstd_static --config Release 43 | } 44 | 45 | clean_deps 46 | download_zstd 47 | build_zstd -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | export declare function compress(data: Buffer, level?: number | undefined | null): Promise; 2 | export declare function decompress(data: Buffer): Promise; 3 | -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const { promisify } = require('util'); 3 | const { isUint8Array } = require('util/types'); 4 | 5 | function load() { 6 | try { 7 | return require('../build/Release/zstd.node'); 8 | } catch { 9 | // Webpack will fail when just returning the require, so we need to wrap 10 | // in a try/catch and rethrow. 11 | /* eslint no-useless-catch: 0 */ 12 | try { 13 | return require('../build/Debug/zstd.node'); 14 | } catch (error) { 15 | throw error; 16 | } 17 | } 18 | } 19 | 20 | const zstd = load(); 21 | 22 | const _compress = promisify(zstd.compress); 23 | const _decompress = promisify(zstd.decompress); 24 | // Error objects created via napi don't have JS stacks; wrap them so .stack is present 25 | // https://github.com/nodejs/node/issues/25318#issuecomment-451068073 26 | 27 | exports.compress = async function compress(data, compressionLevel) { 28 | if (!isUint8Array(data)) { 29 | throw new TypeError(`parameter 'data' must be a Uint8Array.`); 30 | } 31 | 32 | if (compressionLevel != null && typeof compressionLevel !== 'number') { 33 | throw new TypeError(`parameter 'compressionLevel' must be a number.`); 34 | } 35 | 36 | try { 37 | return await _compress(data, compressionLevel ?? 3); 38 | } catch (e) { 39 | throw new Error(`zstd: ${e.message}`); 40 | } 41 | }; 42 | exports.decompress = async function decompress(data) { 43 | if (!isUint8Array(data)) { 44 | throw new TypeError(`parameter 'data' must be a Uint8Array.`); 45 | } 46 | try { 47 | return await _decompress(data); 48 | } catch (e) { 49 | throw new Error(`zstd: ${e.message}`); 50 | } 51 | }; 52 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@mongodb-js/zstd", 3 | "version": "2.0.1", 4 | "main": "lib/index.js", 5 | "types": "index.d.ts", 6 | "repository": "https://github.com/mongodb-js/zstd", 7 | "files": [ 8 | "index.d.ts", 9 | "lib/index.js", 10 | "addon/*", 11 | "binding.gyp" 12 | ], 13 | "dependencies": { 14 | "node-addon-api": "^4.3.0", 15 | "prebuild-install": "^7.1.3" 16 | }, 17 | "license": "Apache-2.0", 18 | "devDependencies": { 19 | "@mongodb-js/zstd": "^1.2.0", 20 | "@typescript-eslint/eslint-plugin": "^8.29.0", 21 | "@wasm-fmt/clang-format": "^19.1.7", 22 | "chai": "^4.5.0", 23 | "eslint": "^9.23.0", 24 | "eslint-config-prettier": "^10.1.1", 25 | "eslint-plugin-prettier": "^5.2.5", 26 | "mocha": "^10.8.2", 27 | "node-gyp": "10.1.0", 28 | "prebuild": "^13.0.1", 29 | "prettier": "^3.5.3" 30 | }, 31 | "engines": { 32 | "node": ">= 16.20.1" 33 | }, 34 | "scripts": { 35 | "install": "prebuild-install --runtime napi || npm run clean-install", 36 | "clean-install": "npm run install-zstd && npm run compile", 37 | "compile": "node-gyp rebuild", 38 | "test": "mocha test/index.test.js", 39 | "install-zstd": "bash etc/install-zstd.sh", 40 | "check:eslint": "ESLINT_USE_FLAT_CONFIG=false eslint *ts lib/*.js test/*.js .*.json", 41 | "clang-format": "clang-format --style=file:.clang-format --Werror -i addon/*", 42 | "check:clang-format": "clang-format --style=file:.clang-format --dry-run --Werror addon/*", 43 | "prebuild": "prebuild --runtime napi --strip --verbose --all" 44 | }, 45 | "overrides": { 46 | "prebuild": { 47 | "node-gyp": "$node-gyp" 48 | } 49 | }, 50 | "binary": { 51 | "napi_versions": [ 52 | 4 53 | ] 54 | }, 55 | "mongodb:zstd_version": "1.5.6" 56 | } -------------------------------------------------------------------------------- /release-please-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "pull-request-header": "Please run the release_notes action before releasing to generate release highlights", 3 | "packages": { 4 | ".": { 5 | "include-component-in-tag": false, 6 | "changelog-path": "HISTORY.md", 7 | "release-type": "node", 8 | "bump-minor-pre-major": false, 9 | "bump-patch-for-minor-pre-major": false, 10 | "draft": false, 11 | "prerelease": false 12 | } 13 | }, 14 | "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json" 15 | } -------------------------------------------------------------------------------- /sbom.json: -------------------------------------------------------------------------------- 1 | { 2 | "components": [ 3 | { 4 | "bom-ref": "pkg:github/facebook/zstd@1.5.6", 5 | "externalReferences": [ 6 | { 7 | "type": "distribution", 8 | "url": "https://github.com/facebook/zstd/archive/refs/tags/1.5.6.tar.gz" 9 | }, 10 | { 11 | "type": "website", 12 | "url": "https://github.com/facebook/zstd/tree/1.5.6" 13 | } 14 | ], 15 | "group": "facebook", 16 | "name": "zstd", 17 | "purl": "pkg:github/facebook/zstd@1.5.6", 18 | "type": "library", 19 | "version": "1.5.6" 20 | } 21 | ], 22 | "dependencies": [ 23 | { 24 | "ref": "pkg:github/facebook/zstd@1.5.6" 25 | } 26 | ], 27 | "metadata": { 28 | "timestamp": "2024-11-22T18:19:11.589830+00:00", 29 | "tools": [ 30 | { 31 | "externalReferences": [ 32 | { 33 | "type": "build-system", 34 | "url": "https://github.com/CycloneDX/cyclonedx-python-lib/actions" 35 | }, 36 | { 37 | "type": "distribution", 38 | "url": "https://pypi.org/project/cyclonedx-python-lib/" 39 | }, 40 | { 41 | "type": "documentation", 42 | "url": "https://cyclonedx-python-library.readthedocs.io/" 43 | }, 44 | { 45 | "type": "issue-tracker", 46 | "url": "https://github.com/CycloneDX/cyclonedx-python-lib/issues" 47 | }, 48 | { 49 | "type": "license", 50 | "url": "https://github.com/CycloneDX/cyclonedx-python-lib/blob/main/LICENSE" 51 | }, 52 | { 53 | "type": "release-notes", 54 | "url": "https://github.com/CycloneDX/cyclonedx-python-lib/blob/main/CHANGELOG.md" 55 | }, 56 | { 57 | "type": "vcs", 58 | "url": "https://github.com/CycloneDX/cyclonedx-python-lib" 59 | }, 60 | { 61 | "type": "website", 62 | "url": "https://github.com/CycloneDX/cyclonedx-python-lib/#readme" 63 | } 64 | ], 65 | "name": "cyclonedx-python-lib", 66 | "vendor": "CycloneDX", 67 | "version": "6.4.4" 68 | } 69 | ] 70 | }, 71 | "serialNumber": "urn:uuid:09d58a28-c1dc-43da-ad85-67c806e16b87", 72 | "version": 1, 73 | "$schema": "http://cyclonedx.org/schema/bom-1.5.schema.json", 74 | "bomFormat": "CycloneDX", 75 | "specVersion": "1.5", 76 | "vulnerabilities": [] 77 | } -------------------------------------------------------------------------------- /test/bundling/webpack/.gitignore: -------------------------------------------------------------------------------- 1 | dist/ 2 | *.tgz -------------------------------------------------------------------------------- /test/bundling/webpack/install_zstd.cjs: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const { execSync } = require('node:child_process'); 4 | const { readFileSync } = require('node:fs'); 5 | const { resolve } = require('node:path'); 6 | 7 | const xtrace = (...args) => { 8 | console.log(`running: ${args[0]}`); 9 | return execSync(...args); 10 | }; 11 | 12 | const zstdRoot = resolve(__dirname, '../../..'); 13 | console.log(`zstd package root: ${zstdRoot}`); 14 | 15 | const zstdVersion = JSON.parse( 16 | readFileSync(resolve(zstdRoot, 'package.json'), { encoding: 'utf8' }) 17 | ).version; 18 | console.log(`zstd Version: ${zstdVersion}`); 19 | 20 | xtrace('npm pack --pack-destination test/bundling/webpack', { cwd: zstdRoot }); 21 | 22 | xtrace(`npm install --no-save mongodb-js-zstd-${zstdVersion}.tgz`); 23 | 24 | console.log('zstd installed!'); 25 | -------------------------------------------------------------------------------- /test/bundling/webpack/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "my-webpack-project", 3 | "version": "1.0.0", 4 | "private": true, 5 | "description": "My webpack project", 6 | "main": "index.js", 7 | "scripts": { 8 | "install:zstd": "node install_zstd.cjs", 9 | "test": "webpack", 10 | "build": "webpack --mode=production --node-env=production", 11 | "build:dev": "webpack --mode=development", 12 | "build:prod": "webpack --mode=production --node-env=production", 13 | "watch": "webpack --watch" 14 | }, 15 | "devDependencies": { 16 | "@webpack-cli/generators": "^3.0.1", 17 | "node-loader": "^2.1.0", 18 | "webpack": "^5.75.0", 19 | "webpack-cli": "^5.0.1" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /test/bundling/webpack/readme.md: -------------------------------------------------------------------------------- 1 | # Webpack zstd setup example 2 | 3 | In order to use zstd with webpack there are two changes beyond the default config file needed: 4 | - Set `experiments: { topLevelAwait: true }` in the top-level config object 5 | - Set `resolve: { fallback: { crypto: false } }` in the top-level config object 6 | - `npm install --save-dev node-loader` and use it to handle all .node files. 7 | 8 | ## Testing 9 | 10 | To use this bundler test: 11 | - Make changes to bson 12 | - run `npm run build` in the root of the repo to rebuild the zstd src 13 | - in this directory run `npm run install:zstd` to install zstd as if it were from npm 14 | - We use a `.tgz` install to make sure we're using exactly what will be published to npm 15 | - run `npm run build` to check that webpack can pull in the changes 16 | -------------------------------------------------------------------------------- /test/bundling/webpack/src/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const zstd = require('@mongodb-js/zstd'); 3 | console.log(zstd); 4 | -------------------------------------------------------------------------------- /test/bundling/webpack/webpack.config.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const path = require('path'); 4 | 5 | const isProduction = process.env.NODE_ENV === 'production'; 6 | 7 | const config = { 8 | entry: './src/index.js', 9 | output: { 10 | path: path.resolve(__dirname, 'dist') 11 | }, 12 | experiments: { topLevelAwait: true }, 13 | target: 'node', 14 | module: { 15 | rules: [ 16 | { 17 | test: /\.node$/i, 18 | loader: 'node-loader' 19 | } 20 | ] 21 | }, 22 | resolve: { 23 | extensions: ['.js', '...', '.node'], 24 | fallback: { crypto: false } 25 | } 26 | }; 27 | 28 | module.exports = () => { 29 | if (isProduction) { 30 | config.mode = 'production'; 31 | } else { 32 | config.mode = 'development'; 33 | } 34 | return config; 35 | }; 36 | -------------------------------------------------------------------------------- /test/index.test.js: -------------------------------------------------------------------------------- 1 | const { test } = require('mocha'); 2 | const { compress, decompress } = require('../lib/index'); 3 | 4 | const { expect } = require('chai'); 5 | 6 | describe('compat tests', function () { 7 | let zstdLegacy; 8 | try { 9 | zstdLegacy = require('@mongodb-js/zstd'); 10 | } catch { 11 | // swallow 12 | } 13 | 14 | const isLinuxs390x = process.platform === 'linux' && process.arch === 's390x'; 15 | if (!isLinuxs390x) { 16 | describe('new compress, old decompress', testSuite(zstdLegacy.decompress, compress)); 17 | describe('old compress, new decompress', testSuite(decompress, zstdLegacy.compress)); 18 | describe('new compress, new decompress', testSuite(decompress, compress)); 19 | } 20 | }); 21 | 22 | describe('decompress', function () { 23 | test('decompress() throws a TypeError', async function () { 24 | expect(await decompress().catch(e => e)) 25 | .to.be.instanceOf(TypeError) 26 | .to.match(/must be a uint8array/i); 27 | }); 28 | 29 | test('decompress() returns a Nodejs buffer', async function () { 30 | const compressed = await compress(Buffer.from([1, 2, 3])); 31 | expect(await decompress(compressed)).to.be.instanceOf(Buffer); 32 | }); 33 | }); 34 | 35 | describe('compress', function () { 36 | test('compress() supports compressionLevel', async function () { 37 | const buffer = Buffer.from(historyFile()); 38 | const unspecified = await compress(buffer); 39 | const specified = await compress(buffer, 22); 40 | 41 | expect(specified.length).to.be.lessThan(unspecified.length); 42 | }); 43 | test('compress() throws a TypeError', async function () { 44 | expect(await compress().catch(e => e)) 45 | .to.be.instanceOf(TypeError) 46 | .to.match(/must be a uint8array/i); 47 | }); 48 | 49 | test('compress() returns a Nodejs buffer', async function () { 50 | expect(await compress(Buffer.from([1, 2, 3]))).to.be.instanceOf(Buffer); 51 | }); 52 | 53 | test('decompress() with empty buffer', async function () { 54 | expect(await decompress(Buffer.from([]))).to.deep.equal(Buffer.from([])); 55 | }); 56 | }); 57 | 58 | /** 59 | * @param {import('../index').decompress} decompress 60 | * @param {import('../index').compress} compress 61 | */ 62 | function testSuite(decompress, compress) { 63 | return function () { 64 | test('empty', async function () { 65 | const input = Buffer.from('', 'utf8'); 66 | const result = await decompress(await compress(input)); 67 | expect(result.toString('utf8')).to.deep.equal(''); 68 | }); 69 | 70 | test('one element', async function () { 71 | const input = Buffer.from('a', 'utf8'); 72 | const result = Buffer.from(await decompress(await compress(input))); 73 | expect(result.toString('utf8')).to.deep.equal('a'); 74 | }); 75 | 76 | test('typical length string', async function () { 77 | const input = Buffer.from('hello, world! my name is bailey', 'utf8'); 78 | const result = Buffer.from(await decompress(await compress(input))); 79 | expect(result.toString('utf8')).to.deep.equal('hello, world! my name is bailey'); 80 | }); 81 | 82 | test('huge array', async function () { 83 | const input_expected = Array.from({ length: 10_000_000 }, () => 'a').join(''); 84 | const input = Buffer.from(input_expected, 'utf8'); 85 | 86 | const result = Buffer.from(await decompress(await compress(input))); 87 | expect(result.toString('utf8')).to.deep.equal(input_expected); 88 | }); 89 | }; 90 | } 91 | 92 | /** 93 | * This function returns a string that, when compressed with compression level 22, 94 | * compresses smaller than the default level 3. This is used to ensure that we handle 95 | * the compression level option. 96 | */ 97 | function historyFile() { 98 | return ` 99 | # Changelog 100 | 101 | All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. 102 | 103 | ## [v2.0.0-alpha.0](https://github.com/mongodb-js/zstd/compare/v1.2.2...v2.0.0-alpha.0) (2024-11-27) 104 | 105 | ### Features 106 | 107 | * **NODE-4569:** add "musl" builds for Alpine Linux ([#12](https://github.com/mongodb-js/zstd/issues/12)) ([b3dedc3](https://github.com/mongodb-js/zstd/commit/b3dedc31a274df1eecb54b9092c8dd270f31c21c)) 108 | * **NODE-6539:** add base napi C++ template with standard Node team tooling ([#28](https://github.com/mongodb-js/zstd/issues/28)) ([8c40b08](https://github.com/mongodb-js/zstd/commit/8c40b08782969c87b85d5d1bea0a753db73cc87f)) 109 | * **NODE-6540:** Add c++ zstd compression API ([#30](https://github.com/mongodb-js/zstd/issues/30)) ([6673245](https://github.com/mongodb-js/zstd/commit/667324522600abc6f731b54a9d9a7c6e92954bef)) 110 | * **NODE-6588:** add ssdlc to zstd ([#43](https://github.com/mongodb-js/zstd/issues/43)) ([016d857](https://github.com/mongodb-js/zstd/commit/016d857ccb76f01ebaf18e01756b571338723a16)) 111 | 112 | ### [1.2.2](https://github.com/mongodb-js/zstd/compare/v1.2.1...v1.2.2) (2024-09-16) 113 | 114 | 115 | ### Bug Fixes 116 | 117 | * **NODE-6381:** use targeting for x86_64 darwin ([#26](https://github.com/mongodb-js/zstd/issues/26)) ([f95c9f6](https://github.com/mongodb-js/zstd/commit/f95c9f6b1e836cce7da4e6955181261110e88487)) 118 | 119 | ### [1.2.1](https://github.com/mongodb-js/zstd/compare/v1.2.0...v1.2.1) (2024-09-06) 120 | 121 | 122 | ### Bug Fixes 123 | 124 | * **NODE-6348:** Wrap thrown errors in JS Error objects with stacks ([#25](https://github.com/mongodb-js/zstd/issues/25)) ([af62c4f](https://github.com/mongodb-js/zstd/commit/af62c4f5f816386ce605c20641ad30cc74bb77e2)) 125 | 126 | ## [1.2.0](https://github.com/mongodb-js/zstd/compare/v1.1.0...v1.2.0) (2023-08-29) 127 | 128 | 129 | ### Bug Fixes 130 | 131 | * **NODE-5177:** update to latest zstd-sys ([#15](https://github.com/mongodb-js/zstd/issues/15)) ([6b6d8ce](https://github.com/mongodb-js/zstd/commit/6b6d8ce098de757c53fd52a09d47aa3e29ed2902)) 132 | 133 | ## [1.1.0](https://github.com/mongodb-js/zstd/compare/v1.0.0...v1.1.0) (2023-01-23) 134 | 135 | 136 | ### Features 137 | 138 | * **NODE-4569:** add "musl" builds for Alpine Linux ([#12](https://github.com/mongodb-js/zstd/issues/12)) ([b3dedc3](https://github.com/mongodb-js/zstd/commit/b3dedc31a274df1eecb54b9092c8dd270f31c21c)) 139 | 140 | ## [1.0.0](https://github.com/mongodb-js/zstd/compare/v0.0.7...v1.0.0) (2022-05-18) 141 | 142 | ### [0.0.7](https://github.com/mongodb-js/zstd/compare/v0.0.6...v0.0.7) (2022-05-18) 143 | 144 | 145 | ### Bug Fixes 146 | 147 | * fix macos arm64 build ([#9](https://github.com/mongodb-js/zstd/issues/9)) ([1ebefde](https://github.com/mongodb-js/zstd/commit/1ebefdedb761b34bcc721a934296d3ac9f0e7a1b)) 148 | 149 | ### [0.0.6](https://github.com/mongodb-js/zstd/compare/v0.0.5...v0.0.6) (2022-05-18) 150 | 151 | 152 | ### Features 153 | 154 | * add readme ([833aa92](https://github.com/mongodb-js/zstd/commit/833aa92213236ef35c4bd79d4c462751a3b4e634)) 155 | * update readme ([49ac44e](https://github.com/mongodb-js/zstd/commit/49ac44efbe9a4ab544958b97ae178b51cac057ff)) 156 | 157 | ### [0.0.5](https://github.com/mongodb-js/zstd/compare/v0.0.4...v0.0.5) (2022-05-09) 158 | 159 | 160 | ### Bug Fixes 161 | 162 | * remove 686 win build ([ea36ddc](https://github.com/mongodb-js/zstd/commit/ea36ddc0ce3e6630321e7074a138f2d45dd16f4f)) 163 | 164 | ### [0.0.4](https://github.com/mongodb-js/zstd/compare/v0.0.3...v0.0.4) (2022-05-06) 165 | 166 | 167 | ### Features 168 | 169 | * **NODE-1837:** support passing compression level ([2c1a917](https://github.com/mongodb-js/zstd/commit/2c1a9171c689c1fc87428d383ffeb823291f84cf)) 170 | 171 | ### [0.0.3](https://github.com/mongodb-js/zstd/compare/v0.0.2...v0.0.3) (2022-05-06) 172 | 173 | 174 | ### Bug Fixes 175 | 176 | * update publish task regex ([b62d9b0](https://github.com/mongodb-js/zstd/commit/b62d9b0e644c85d3443f738d953ae7816d3eba00)) 177 | 178 | ### [0.0.2](https://github.com/mongodb-js/zstd/compare/v0.0.1...v0.0.2) (2022-05-06) 179 | 180 | 181 | ### Bug Fixes 182 | 183 | * dont use org in napi name ([9063ea8](https://github.com/mongodb-js/zstd/commit/9063ea8bb7b187aacd876f75b3e74bc0188e7a2b)) 184 | 185 | ### 0.0.1 (2022-05-05) 186 | 187 | 188 | ### Features 189 | 190 | * add release script ([c2c1783](https://github.com/mongodb-js/zstd/commit/c2c1783242766c8b65f57838494d1a3c4dc23305)) 191 | * add standard version ([f63a9b9](https://github.com/mongodb-js/zstd/commit/f63a9b95ba261004cb2f481ff201fa2e116d3aed)) 192 | * initial project setup ([53671a3](https://github.com/mongodb-js/zstd/commit/53671a393326605650d3ae12959796a6c6976472)) 193 | * update package.json files ([7823f1b](https://github.com/mongodb-js/zstd/commit/7823f1b3156f4eacd2c235ac660aa9810eee6f84)) 194 | * update to idomatic rust ([16e215a](https://github.com/mongodb-js/zstd/commit/16e215a59817fdf94bb62c8620b49b6255bafda0)) 195 | 196 | 197 | ### Bug Fixes 198 | 199 | * handle status in error ([e29c0ed](https://github.com/mongodb-js/zstd/commit/e29c0ed3b1077987c28bc4daa11c5d6a01c650cf)) 200 | * remove debug js ([c454785](https://github.com/mongodb-js/zstd/commit/c454785a6cbfe63ed21ca3942ce0707e0b399d3f)) 201 | `; 202 | } 203 | --------------------------------------------------------------------------------