@ably/vcdiff-decoder 中文文档教程
Vcdiff Decoder
用纯 JavaScript 编写的 Vcdiff 解码器。 支持 Vcdiff 格式,如 RFC 3284 中所指定。
使用从生成的 Vcdiff 补丁/增量文件进行测试和验证 谷歌的open-vcdiff 和 Joshua MacDonald 的 xdelta。
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 latest1.*
versionhttps://cdn.ably.io/lib/vcdiff-decoder.min-1.0.js
for latestv1.0.*
versionhttps://cdn.ably.io/lib/vcdiff-decoder.min-1.0.3.js
for version1.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 transformsource
to the returned targetsource
:Uint8Array
- the group of bytes to transform to the returned target using by applyingdelta
返回一个 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.js
和 vcdiff-decoder.min.js
。
Testing
要运行所有测试,请使用:
npm test
支持的浏览器测试
您需要为 BROWSERSTACK_USERNAME
和 BROWSERSTACK_ACCESSKEY
配置环境变量。
Release Procedure
在 main
分支上:
- 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 runningnpm run grunt -- release:patch
(or "major", "minor" or "prepatch" as appropriate - see grunt-bump Usage Examples) - Release the tagged commit to Github using
git push origin main --follow-tags
- Release to NPM using
npm publish . --access public
(this package is configured to require that 2FA is used by publishers) - Release to Ably's CDN using
npm run grunt -- publish-cdn
(operable by Ably staff only) - Visit tags and draft new release for the newly created tag
Vcdiff Decoder
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 latest1.*
versionhttps://cdn.ably.io/lib/vcdiff-decoder.min-1.0.js
for latestv1.0.*
versionhttps://cdn.ably.io/lib/vcdiff-decoder.min-1.0.3.js
for version1.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 transformsource
to the returned targetsource
:Uint8Array
- the group of bytes to transform to the returned target using by applyingdelta
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:
- 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 runningnpm run grunt -- release:patch
(or "major", "minor" or "prepatch" as appropriate - see grunt-bump Usage Examples) - Release the tagged commit to Github using
git push origin main --follow-tags
- Release to NPM using
npm publish . --access public
(this package is configured to require that 2FA is used by publishers) - Release to Ably's CDN using
npm run grunt -- publish-cdn
(operable by Ably staff only) - Visit tags and draft new release for the newly created tag