@ably/vcdiff-decoder

中文文档
1.0.6发布于 2023/11/27Apache-2.0TypeScriptESM + CJS零依赖近 30 天下载 3.9万

Pure JavaScript Vcdiff decoder that works with binary deltas from Google's open-vcdiff

原始使用文档
文档目录10 节
  1. Installation from npm for Node.js
  2. Script include for Web Browsers
  3. Usage
  4. Exported Functions
  5. decode(delta, source)
  6. Contributing
  7. Requirements
  8. Building
  9. Testing
  10. Release Procedure

Vcdiff Decoder

Build Status npm version

A Vcdiff decoder written in pure JavaScript. Supports the Vcdiff format, as specified in RFC 3284.

Tested and proven with Vcdiff patch/delta files generated from Google's open-vcdiff and Joshua MacDonald's xdelta.

Installation from npm for Node.js

npm install @ably/vcdiff-decoder

and require as:

const vcdiffPlugin = require('@ably/vcdiff-decoder');

Script include for Web Browsers

Include the library in your HTML from our CDN:

<script src="https://cdn.ably.io/lib/vcdiff-decoder.min-1.js"></script>

We follow Semantic Versioning. To lock into a major or minor version of the client library, you can specify a specific version number - for example:

  • https://cdn.ably.io/lib/vcdiff-decoder.min-1.js for latest 1.* version
  • https://cdn.ably.io/lib/vcdiff-decoder.min-1.0.js for latest v1.0.* version
  • https://cdn.ably.io/lib/vcdiff-decoder.min-1.0.3.js for version 1.0.3 explicitly

You can load the non-minified version by omitting min- from the URL, for example https://cdn.ably.io/lib/vcdiff-decoder-1.js.

See tagged releases for available versions.

Usage

The following code sample shows how to use Vcdiff with Ably:

const Ably = require('ably');
const vcdiffPlugin = require('@ably/vcdiff-decoder');

const realtime = new Ably.Realtime({
    key: 'YOUR_ABLY_KEY',
    plugins: {
        vcdiff: vcdiffPlugin
    },
    log: { level: 4 } // optional
});

const channel = realtime.channels.get('your-ably-channel', {
    params: {
        delta: 'vcdiff'
    }
});

channel.subscribe(msg => console.log("Received message: ", msg));

Exported Functions

decode(delta, source)

Synchronous decode. Parameters:

  • delta: Uint8Array - the binary Vcdiff format encoding of the patch/diff information needed to transform source to the returned target
  • source: Uint8Array - the group of bytes to transform to the returned target using by applying delta

Returns a Uint8Array, the 'target', being the result of applying delta to source.

Contributing

Requirements

Node.js

The vcdiff dev dependency of this project, used for testing, fails to build against Node.js 9 and newer. For this reason, until #3 has been addressed, the tests must be run against an environment with Node.js 8 installed.

At the time of writing this means:

vcdiff-decoder % node --version
v8.17.0
vcdiff-decoder % npm --version
6.13.4

For those who use ASDF or compatible tooling to manage their Node.js runtime versions, we have included a .tool-versions file.

Python

The version of node-gyp bundled with the above-mentioned version of NPM uses an API that was removed in Python 3.9, causing npm install to fail. So, you must use Python 3.8 or earlier.

For those who use ASDF or compatible tooling to manage their Python runtime versions, we have included a .tool-versions file.

Building

You can trigger a build using Webpack with:

npm run grunt -- build

which creates vcdiff-decoder.js and vcdiff-decoder.min.js in the dist folder, and vcdiff-decoder.js in the build/cjs folder.

Testing

To run all tests use:

npm test

Browser testing supported by

for which you will need to configure environment variables for BROWSERSTACK_USERNAME and BROWSERSTACK_ACCESSKEY.

Release Procedure

On the main branch:

  1. Increment the version, regenerate from source (a.k.a. build / bundle) and make a tagged commit which includes the built output from the /dist and /build folders by running npm run grunt -- release:patch (or "major", "minor" or "prepatch" as appropriate - see grunt-bump Usage Examples)
  2. Release the tagged commit to Github using git push origin main --follow-tags
  3. Release to NPM using npm publish . --access public (this package is configured to require that 2FA is used by publishers)
  4. Release to Ably's CDN using npm run grunt -- publish-cdn (operable by Ably staff only)
  5. Visit tags and draft new release for the newly created tag

版本与发布记录

@ably/vcdiff-decoder 共发布 7 个版本,首次发布于 2019/07/30;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.6latest2023/11/272 年前
1.0.52022/02/114 年前
1.0.42020/04/296 年前
1.0.32020/04/296 年前
1.0.22020/04/176 年前
1.0.12019/07/307 年前

关于 @ably/vcdiff-decoder 的常见问题

@ably/vcdiff-decoder 是什么?

Pure JavaScript Vcdiff decoder that works with binary deltas from Google's open-vcdiff

如何安装 @ably/vcdiff-decoder?

在项目目录运行 npm install @ably/vcdiff-decoder,或使用 pnpm add / yarn add / bun add。

@ably/vcdiff-decoder 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@ably/vcdiff-decoder 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@ably/vcdiff-decoder 可以商用吗?

@ably/vcdiff-decoder 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@ably/vcdiff-decoder 的下载量有多少?

根据 npm 官方下载统计,@ably/vcdiff-decoder 在 2026/10/05 – 2026/11/03 这 30 天内被下载 39,292 次,日均约 1,310 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ably/vcdiff-decoder 还在维护吗?

最新版本 1.0.6 发布于 2023/11/27(2 年前);至今共发布 7 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/07/30。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。