@ably/vcdiff-decoder 中文文档教程

发布于 3年前 浏览 29 项目主页 更新于 3年前

Vcdiff Decoder

构建状态npm version

用纯 JavaScript 编写的 Vcdiff 解码器。 支持 Vcdiff 格式,如 RFC 3284 中所指定。

使用从生成的 Vcdiff 补丁/增量文件进行测试和验证 谷歌open-vcdiffJoshua MacDonaldxdelta

Installation from npm for Node.js

npm install @ably/vcdiff-decoder

并要求为:

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

Script include for Web Browsers

从我们的 CDN 将库包含在您的 HTML 中:

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

我们遵循语义版本控制。 要锁定客户端库的主要或次要版本,您可以指定特定的版本号 - 例如:

  • 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

您可以通过从 URL 中省略 min- 来加载非缩小版本,例如 <代码>https://cdn.ably.io/lib/vcdiff-decoder-1.js。

有关可用版本,请参阅标记的版本

Usage

以下代码示例显示了如何将 Vcdiff 与 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)

同步解码​​。 参数:

  • 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

返回一个 Uint8Array,即“目标”,是将 delta 应用于 source 的结果。

Contributing

Requirements

此项目用于测试的 vcdiff 开发依赖项无法针对 Node 进行构建。 js 9 及更新版本。 出于这个原因,在解决 #3 之前,测试必须针对具有Node.js 8 安装。

在撰写本文时,这意味着:

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

对于那些使用 ASDF 或兼容的工具来管理他们的 Node.js 运行时版本,我们已经包含了一个 .tool-versions 文件。

Building

您可以使用 Webpack 触发构建:

npm run grunt -- build

dist 文件夹中创建 vcdiff-decoder.jsvcdiff-decoder.min.js

Testing

要运行所有测试,请使用:

npm test

支持的浏览器测试

您需要为 BROWSERSTACK_USERNAMEBROWSERSTACK_ACCESSKEY 配置环境变量。

Release Procedure

main 分支上:

  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 folder 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

Vcdiff Decoder

Build Statusnpm 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

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.

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.

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 folder 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
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文