Skip to content

Commit

Permalink
升级到 v12.10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
h7lin committed Sep 8, 2019
1 parent c1a3428 commit 5207cf2
Show file tree
Hide file tree
Showing 220 changed files with 688 additions and 284 deletions.
6 changes: 4 additions & 2 deletions assert/class_assert_assertionerror.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

`Error` 的子类,表明断言的失败。
`assert` 模块抛出的所有错误都是 `AssertionError` 类的实例。
* 继承自: {errors.Error}

表明断言的失败。
`assert` 模块抛出的所有错误都将是 `AssertionError` 类的实例。

7 changes: 5 additions & 2 deletions child_process/class_childprocess.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
added: v2.2.0
-->

`ChildProcess` 类的实例都是 [`EventEmitter`],表示衍生的子进程。
* 继承自: {EventEmitter}

`ChildProcess` 的实例不是直接创建的,而是使用 [`child_process.spawn()`][`child_process.exec()`][`child_process.execFile()`] [`child_process.fork()`] 方法来创建 `ChildProcess` 的实例。
`ChildProcess` 的实例代表衍生的子进程。

`ChildProcess` 的实例不是直接创建的。
而是,使用 [`child_process.spawn()`][`child_process.exec()`][`child_process.execFile()`] [`child_process.fork()`] 方法来创建 `ChildProcess` 的实例。

1 change: 1 addition & 0 deletions cli/completion_bash.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ added: v10.12.0
-->

Print source-able bash completion script for Node.js.

```console
$ node --completion-bash > node_bash_completion
$ source node_bash_completion
Expand Down
3 changes: 3 additions & 0 deletions cli/frozen_intrinsics.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ Support is currently only provided for the root context and no guarantees are
currently provided that `global.Array` is indeed the default intrinsic
reference. Code may break under this flag.

`--require` runs prior to freezing intrinsics in order to allow polyfills to
be added.

1 change: 1 addition & 0 deletions cli/node_options_options.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ Node.js options that are allowed are:
V8 options that are allowed are:
<!-- node-options-v8 start -->
- `--abort-on-uncaught-exception`
- `--interpreted-frames-native-stack`
- `--max-old-space-size`
- `--perf-basic-prof-only-functions`
- `--perf-basic-prof`
Expand Down
8 changes: 5 additions & 3 deletions cluster/class_worker.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
added: v0.7.0
-->

`Worker` 对象包含了关于工作进程的所有公共信息和方法。
在主进程里,可以使用 `cluster.workers` 来获取它。
在工作进程里,可以使用 `cluster.worker` 来获取它。
* 继承自: {EventEmitter}

`Worker` 对象包含了关于工作进程的所有的公共的信息和方法。
在主进程中,可以使用 `cluster.workers` 来获取它。
在工作进程中,可以使用 `cluster.worker` 来获取它。

44 changes: 23 additions & 21 deletions crypto/class_cipher.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,29 @@
added: v0.1.94
-->

* 继承自: {stream.Transform}

`Cipher` 类的实例用于加密数据。
这个类可以用在以下两种方法中的一种:
该类可以通过以下两种方式之一使用:

- 作为[][stream]既可读又可写,未加密数据的编写是为了在可读的方面生成加密的数据
- 使用 [`cipher.update()`][] [`cipher.final()`][] 方法产生加密的数据
- 作为可读写的[][stream]其中写入未加密的数据以在可读侧生成加密的数据
- 使用 [`cipher.update()`] [`cipher.final()`] 方法生成加密的数据

[`crypto.createCipher()`][] [`crypto.createCipheriv()`][] 方法用于创建 `Cipher` 实例。
`Cipher` 对象不能直接使用 `new` 关键字创建
[`crypto.createCipher()`] [`crypto.createCipheriv()`] 方法用于创建 `Cipher` 实例。
不能使用 `new` 关键字直接地创建 `Cipher` 对象

示例,使用` Cipher` 对象作为流:
示例,使用 `Cipher` 对象作为流

```js
const crypto = require('crypto');
const algorithm = 'aes-192-cbc';
const password = 'Password used to generate key';
const password = '用于生成密钥的密码';
// 密钥长度取决于算法。
// 在这种情况下,对于 aes192,它是 24 字节(192 位)。
// 在此示例中,对于 aes192,它是 24 个字节(192 位)。
// 改为使用异步的 `crypto.scrypt()`。
const key = crypto.scryptSync(password, 'salt', 24);
// 使用 `crypto.randomBytes()` 生成随机 iv 而不是此处显示的静态 iv。
// 使用 `crypto.randomBytes()` 生成随机的 iv 而不是此处显示的静态的 iv。
const iv = Buffer.alloc(16, 0); // 初始化向量。
const cipher = crypto.createCipheriv(algorithm, key, iv);
Expand All @@ -36,51 +38,51 @@ cipher.on('readable', () => {
});
cipher.on('end', () => {
console.log(encrypted);
// 打印: e5f79c5915c02171eec6b212d5520d44480993d7d622a7c4c2da32f6efda0ffa
// 打印: 3accbdcaf5574941a9c879da51711ffc2a5a017757fa736eacc579b9088ba712
});
cipher.write('some clear text data');
cipher.write('要加密的数据');
cipher.end();
```

示例,使用 `Cipher` 和管道流:
示例,使用 `Cipher` 和管道流

```js
const crypto = require('crypto');
const fs = require('fs');
const algorithm = 'aes-192-cbc';
const password = 'Password used to generate key';
const password = '用于生成密钥的密码';
// 改为使用异步的 `crypto.scrypt()`。
const key = crypto.scryptSync(password, 'salt', 24);
// 使用 `crypto.randomBytes()` 生成随机 iv 而不是此处显示的静态 iv。
// 使用 `crypto.randomBytes()` 生成随机的 iv 而不是此处显示的静态的 iv。
const iv = Buffer.alloc(16, 0); // 初始化向量。
const cipher = crypto.createCipheriv(algorithm, key, iv);
const input = fs.createReadStream('test.js');
const output = fs.createWriteStream('test.enc');
const input = fs.createReadStream('要加密的数据.txt');
const output = fs.createWriteStream('加密后的数据.enc');
input.pipe(cipher).pipe(output);
```

示例,使用 [`cipher.update()`][] [`cipher.final()`][] 方法:
示例,使用 [`cipher.update()`] [`cipher.final()`] 方法:

```js
const crypto = require('crypto');
const algorithm = 'aes-192-cbc';
const password = 'Password used to generate key';
const password = '用于生成密钥的密码';
// 改为使用异步的 `crypto.scrypt()`。
const key = crypto.scryptSync(password, 'salt', 24);
// 使用 `crypto.randomBytes()` 生成随机 iv 而不是此处显示的静态 iv。
// 使用 `crypto.randomBytes()` 生成随机的 iv 而不是此处显示的静态的 iv。
const iv = Buffer.alloc(16, 0); // 初始化向量。
const cipher = crypto.createCipheriv(algorithm, key, iv);
let encrypted = cipher.update('some clear text data', 'utf8', 'hex');
let encrypted = cipher.update('要加密的数据', 'utf8', 'hex');
encrypted += cipher.final('hex');
console.log(encrypted);
// 打印: e5f79c5915c02171eec6b212d5520d44480993d7d622a7c4c2da32f6efda0ffa
// 打印: 3accbdcaf5574941a9c879da51711ffc2a5a017757fa736eacc579b9088ba712
```

39 changes: 21 additions & 18 deletions crypto/class_decipher.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,26 @@
added: v0.1.94
-->

`Decipher` 类的实例用于解密数据。这个类可以用在以下两种方法中的一种:
* 继承自: {stream.Transform}

- 作为[][stream],既可读又可写,加密数据的编写是为了在可读的方面生成未加密的数据
- 使用 [`decipher.update()`][] [`decipher.final()`][] 方法产生未加密的数据。
`Decipher` 类的实例用于解密数据
该类可以通过以下两种方式之一使用:

[`crypto.createDecipher()`][] [`crypto.createDecipheriv()`][] 的方法用于创建`Decipher`实例。
`Decipher` 对象不能直接使用 `new` 关键字创建。
- 作为可读写的[][stream],其中写入加密的数据以在可读侧生成未加密的数据。
- 使用 [`decipher.update()`] [`decipher.final()`] 方法生成未加密的数据。

[`crypto.createDecipher()`] [`crypto.createDecipheriv()`] 方法用于创建 `Decipher` 实例。
不能使用 `new` 关键字直接地创建 `Decipher` 对象。

示例,使用 `Decipher` 对象作为流:

```js
const crypto = require('crypto');
const algorithm = 'aes-192-cbc';
const password = 'Password used to generate key';
const password = '用于生成密钥的密码';
// 密钥长度取决于算法。
// 在这种情况下,对于 aes192,它是 24 字节(192 位)。
// 在此示例中,对于 aes192,它是 24 个字节(192 位)。
// 改为使用异步的 `crypto.scrypt()`。
const key = crypto.scryptSync(password, 'salt', 24);
// IV 通常与密文一起传递。
Expand All @@ -34,12 +37,12 @@ decipher.on('readable', () => {
});
decipher.on('end', () => {
console.log(decrypted);
// 打印: some clear text data
// 打印: 要加密的数据
});
// 使用相同的算法密钥和 iv 加密
// 使用相同的算法密钥和 iv 进行加密
const encrypted =
'e5f79c5915c02171eec6b212d5520d44480993d7d622a7c4c2da32f6efda0ffa';
'3accbdcaf5574941a9c879da51711ffc2a5a017757fa736eacc579b9088ba712';
decipher.write(encrypted, 'hex');
decipher.end();
```
Expand All @@ -51,40 +54,40 @@ const crypto = require('crypto');
const fs = require('fs');
const algorithm = 'aes-192-cbc';
const password = 'Password used to generate key';
const password = '用于生成密钥的密码';
// 改为使用异步的 `crypto.scrypt()`。
const key = crypto.scryptSync(password, 'salt', 24);
// IV 通常与密文一起传递。
const iv = Buffer.alloc(16, 0); // 初始化向量。
const decipher = crypto.createDecipheriv(algorithm, key, iv);
const input = fs.createReadStream('test.enc');
const output = fs.createWriteStream('test.js');
const input = fs.createReadStream('要解密的数据.enc');
const output = fs.createWriteStream('解密后的数据.js');
input.pipe(decipher).pipe(output);
```

示例,使用 [`decipher.update()`][] [`decipher.final()`][] 方法:
示例,使用 [`decipher.update()`] [`decipher.final()`] 方法:

```js
const crypto = require('crypto');
const algorithm = 'aes-192-cbc';
const password = 'Password used to generate key';
const password = '用于生成密钥的密码';
// 改为使用异步的 `crypto.scrypt()`。
const key = crypto.scryptSync(password, 'salt', 24);
// IV 通常与密文一起传递。
const iv = Buffer.alloc(16, 0); // 初始化向量。
const decipher = crypto.createDecipheriv(algorithm, key, iv);
// 使用相同的算法密钥和 iv 加密
// 使用相同的算法密钥和 iv 进行加密
const encrypted =
'e5f79c5915c02171eec6b212d5520d44480993d7d622a7c4c2da32f6efda0ffa';
'3accbdcaf5574941a9c879da51711ffc2a5a017757fa736eacc579b9088ba712';
let decrypted = decipher.update(encrypted, 'hex', 'utf8');
decrypted += decipher.final('utf8');
console.log(decrypted);
// 打印: some clear text data
// 打印: 要加密的数据
```

1 change: 1 addition & 0 deletions crypto/class_diffiehellmangroup.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const dh = crypto.createDiffieHellmanGroup(name);
```
`name` is taken from [RFC 2412][] (modp1 and 2) and [RFC 3526][]:
```console
$ perl -ne 'print "$1\n" if /"(modp\d+)"/' src/node_crypto_groups.h
modp1 # 768 bits
Expand Down
26 changes: 15 additions & 11 deletions crypto/class_hash.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
<!-- YAML
added: v0.1.92
-->
`Hash` 类是用于创建数据哈希值的工具类。它能用以下方法使用:

- 作为[][stream],既可读又可写,数据被写入要在可读的方面生成一个计算散列摘要。
- 使用 [`hash.update()`][] [`hash.digest()`][] 方法产生计算后的哈希。
* 继承自: {stream.Transform}

[`crypto.createHash()`][] 方法用于创建 `Hash` 实例。
`Hash` 不能直接使用 `new` 关键字创建对象。
`Hash` 类是一个实用工具,用于创建数据的哈希摘要。
它可以通过以下两种方式之一使用:

- 作为可读写的[][stream],其中写入数据以在可读侧生成计算后的哈希摘要。
- 使用 [`hash.update()`] [`hash.digest()`] 方法生成计算后的哈希。

[`crypto.createHash()`] 方法用于创建 `Hash` 实例。
不能使用 `new` 关键字直接地创建 `Hash` 对象。

示例,使用 `Hash` 对象作为流:

Expand All @@ -21,11 +25,11 @@ hash.on('readable', () => {
if (data) {
console.log(data.toString('hex'));
// 打印:
// 6a2da20943931e9834fc12cfe5bb47bbd9ae43489a30726962b576f4e3993e50
// 164345eba9bccbafb94b27b8299d49cc2d80627fc9995b03230965e6d8bcbf56
}
});
hash.write('some data to hash');
hash.write('要创建哈希摘要的数据');
hash.end();
```

Expand All @@ -36,19 +40,19 @@ const crypto = require('crypto');
const fs = require('fs');
const hash = crypto.createHash('sha256');
const input = fs.createReadStream('test.js');
const input = fs.createReadStream('要创建哈希摘要的数据.txt');
input.pipe(hash).pipe(process.stdout);
```

示例,使用 [`hash.update()`][] [`hash.digest()`][] 方法:
示例,使用 [`hash.update()`] [`hash.digest()`] 方法:

```js
const crypto = require('crypto');
const hash = crypto.createHash('sha256');
hash.update('some data to hash');
hash.update('要创建哈希摘要的数据');
console.log(hash.digest('hex'));
// 打印:
// 6a2da20943931e9834fc12cfe5bb47bbd9ae43489a30726962b576f4e3993e50
// 164345eba9bccbafb94b27b8299d49cc2d80627fc9995b03230965e6d8bcbf56
```

Loading

0 comments on commit 5207cf2

Please sign in to comment.