Skip to content

Commit

Permalink
polish
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaciras committed Sep 13, 2020
1 parent 9e64c8d commit 6db97d8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Kaciras 博客的 Node 本地扩展,包含了一些需要在底层实现的功能。

[![Build Status](https://travis-ci.org/kaciras-blog/nativelib.svg?branch=master)](https://travis-ci.org/kaciras-blog/nativelib)

## xxHash

[xxHash](https://github.com/Cyan4973/xxHash) 是一个非加密 Hash 函数系列,拥有很快的运算速度。
Expand All @@ -8,12 +10,12 @@ Kaciras 博客的 Node 本地扩展,包含了一些需要在底层实现的功

# 安装

安装前需要配置编译环境,详见 [https://github.com/nodejs/node-gyp#installation](https://github.com/nodejs/node-gyp#installation)

```shell script
yarn add git://github.com/kaciras-blog/nativelib#v0.1.1
yarn add git://github.com/kaciras-blog/nativelib#v0.2.1 [--no-prebuild]
```

默认情况将从 GitHub Release 上下载编译好的二进制文件,如果需要自己编译请添加`--no-prebuild`参数。

# 用法

## xxHash
Expand All @@ -36,3 +38,5 @@ const { xxHash3_128 } = require("xxhash-native");
console.log(xxHash3_128("xxhash", "base64u"));
// nItDfHjKwAo3YHLiS_300g==
```

xxHash 算法非常快,故没有提供异步的版本。
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kaciras-blog/nativelib",
"version": "0.2.0",
"version": "0.2.1",
"description": "Node.js native addon for kaciras blog",
"license": "MIT",
"author": "Kaciras <[email protected]>",
Expand Down
10 changes: 10 additions & 0 deletions script/prebuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ function handleError(error) {
process.exit(2);
}

/**
* 获取当前环境下的压缩包名,跟 prebuild 的一致。
*/
function getPackageName() {
const name = packageJson.name.split("/").pop();
const { version } = packageJson;
Expand All @@ -40,6 +43,10 @@ function getGithubRelease() {
return `https://${match[0]}/releases/download/v${version}`.replace(/\.git$/, "");
}

/**
* 打包编译好的二进制文件,并使用 brotli 算法压缩(brotli 比 gzip 压缩率高20%)。
* 注意本命令只打包,不负责编译和上传,这两个步骤需要 CI 来完成。
*/
function pack() {
fs.rmdirSync("prebuilds", { recursive: true });
fs.mkdirSync("prebuilds");
Expand All @@ -52,6 +59,9 @@ function pack() {
.pipe(fs.createWriteStream(`prebuilds/${getPackageName()}`));
}

/**
* 从 GitHub Release 上下载预编译好的文件并解压。
*/
function download() {
const url = `${getGithubRelease()}/${getPackageName()}`;
const request = https.get(url);
Expand Down

0 comments on commit 6db97d8

Please sign in to comment.