Skip to content

Commit

Permalink
升级到 v6.10.3
Browse files Browse the repository at this point in the history
  • Loading branch information
h7lin committed May 3, 2017
1 parent 8e1ef24 commit a794e61
Show file tree
Hide file tree
Showing 55 changed files with 174 additions and 175 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# node-api-cn
Node.js API 中文文档 v6.10.2
Node.js API 中文文档 v6.10.3

http://nodejs.cn/api/
15 changes: 0 additions & 15 deletions assert/assert_value_message.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,3 @@ added: v0.5.9

[`assert.ok()`] 的别名。

```js
const assert = require('assert');
assert(true);
// 通过
assert(1);
// 通过
assert(false);
// 抛出 "AssertionError: false == true"
assert(0);
// 抛出 "AssertionError: 0 == true"
assert(false, '不是真值');
// 抛出 "AssertionError: 不是真值"
```

2 changes: 2 additions & 0 deletions buffer/buf_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ name: [index]
索引操作符 `[index]` 可用于获取或设置 `buf` 中指定 `index` 位置的八位字节。
这个值指向的是单个字节,所以合法的值范围是的 `0x00` `0xFF`(十六进制),或 `0` `255`(十进制)。

该操作符继承自 `Uint8Array`,所以它对越界访问的处理与 `UInt8Array` 相同(也就是说,获取时返回 `undefined`,设置时什么也不做)。

例如:拷贝一个 ASCII 字符串到一个 `Buffer`,每次一个字节。

```js
Expand Down
8 changes: 4 additions & 4 deletions buffer/buffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ const buf3 = Buffer.allocUnsafe(10);
// 创建一个包含 [0x1, 0x2, 0x3] 的 Buffer。
const buf4 = Buffer.from([1, 2, 3]);
// 创建一个包含 ASCII 字节数组 [0x74, 0x65, 0x73, 0x74] 的 Buffer。
const buf5 = Buffer.from('test');
// 创建一个包含 UTF-8 字节数组 [0x74, 0xc3, 0xa9, 0x73, 0x74] 的 Buffer。
const buf6 = Buffer.from('tést', 'utf8');
const buf5 = Buffer.from('tést');
// 创建一个包含 Latin-1 字节数组 [0x74, 0xe9, 0x73, 0x74] 的 Buffer。
const buf6 = Buffer.from('tést', 'latin-1');
```

2 changes: 1 addition & 1 deletion buffer/class_method_buffer_from_array.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ added: v5.10.0
例子:

```js
// 创建一个新的包含字符串 'buffer' 的 ASCII 字节的 Buffer
// 创建一个新的包含字符串 'buffer' 的 UTF-8 字节的 Buffer
const buf = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);
```

Expand Down
10 changes: 5 additions & 5 deletions buffer/class_method_buffer_from_arraybuffer_byteoffset_length.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
added: v5.10.0
-->

* `arrayBuffer` {ArrayBuffer} [`TypedArray`] [`ArrayBuffer`] `.buffer` 属性
* `byteOffset` {Integer} `arrayBuffer` 开始拷贝的位置。 **默认:** `0`
* `length` {Integer} `arrayBuffer` 拷贝多少字节。
**默认:** `arrayBuffer.length - byteOffset`
* `arrayBuffer` {ArrayBuffer} 一个 [`ArrayBuffer`],或一个 [`TypedArray`] `.buffer` 属性。
* `byteOffset` {Integer} 开始拷贝的索引。默认为 `0`
* `length` {Integer} 拷贝的字节数。默认为 `arrayBuffer.length - byteOffset`

当传入一个 [`TypedArray`] 实例的 `.buffer` 属性的引用时,这个新建的 `Buffer` 会像 [`TypedArray`] 那样共享同一分配的内存。
This creates a view of the [`ArrayBuffer`] without copying the underlying memory.
例如,当传入一个 [`TypedArray`] 实例的 `.buffer` 属性的引用时,这个新建的 `Buffer` 会像 [`TypedArray`] 那样共享同一分配的内存。

例子:

Expand Down
2 changes: 1 addition & 1 deletion buffer/new_buffer_array.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Allocates a new `Buffer` using an `array` of octets.
Example:

```js
// Creates a new Buffer containing the ASCII bytes of the string 'buffer'
// Creates a new Buffer containing the UTF-8 bytes of the string 'buffer'
const buf = new Buffer([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);
```

15 changes: 8 additions & 7 deletions buffer/new_buffer_arraybuffer_byteoffset_length.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ deprecated: v6.0.0

> 稳定性: 0 - 废弃的: 使用 [`Buffer.from(arrayBuffer[, byteOffset [, length]])`][`Buffer.from(arrayBuffer)`] 代替。

* `arrayBuffer` {ArrayBuffer} The `.buffer` property of a [`TypedArray`] or
[`ArrayBuffer`]
* `byteOffset` {Integer} Where to start copying from `arrayBuffer`. **Default:** `0`
* `length` {Integer} How many bytes to copy from `arrayBuffer`.
* `arrayBuffer` {ArrayBuffer} An [`ArrayBuffer`] or the `.buffer` property of a
[`TypedArray`].
* `byteOffset` {Integer} Index of first byte to expose. **Default:** `0`
* `length` {Integer} Number of bytes to expose.
**Default:** `arrayBuffer.length - byteOffset`

When passed a reference to the `.buffer` property of a [`TypedArray`] instance,
the newly created `Buffer` will share the same allocated memory as the
[`TypedArray`].
This creates a view of the [`ArrayBuffer`] without copying the underlying
memory. For example, when passed a reference to the `.buffer` property of a
[`TypedArray`] instance, the newly created `Buffer` will share the same
allocated memory as the [`TypedArray`].

The optional `byteOffset` and `length` arguments specify a memory range within
the `arrayBuffer` that will be shared by the `Buffer`.
Expand Down
2 changes: 1 addition & 1 deletion child_process/child_stderr.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ added: v0.1.90

一个代表子进程的 `stderr` 的可读流。

如果子进程被衍生时 `stdio[2]` 被设为任何不是 `'pipe'` 的值,则这会是 `undefined`
如果子进程被衍生时 `stdio[2]` 被设为任何不是 `'pipe'` 的值,则这会是 `null`

`child.stderr` `child.stdio[2]` 的一个别名。
这两个属性指向相同的值。
Expand Down
2 changes: 1 addition & 1 deletion child_process/child_stdin.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ added: v0.1.90

注意,如果一个子进程正在等待读取所有的输入,则子进程不会继续直到流已通过 `end()` 关闭。

如果子进程被衍生时 `stdio[0]` 被设为任何不是 `'pipe'` 的值,则这会是 `undefined`
如果子进程被衍生时 `stdio[0]` 被设为任何不是 `'pipe'` 的值,则这会是 `null`

`child.stdin` `child.stdio[0]` 的一个别名。
这两个属性指向相同的值。
Expand Down
2 changes: 1 addition & 1 deletion child_process/child_stdout.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ added: v0.1.90

一个代表子进程的 `stdout` 的可读流。

如果子进程被衍生时 `stdio[1]` 被设为任何不是 `'pipe'` 的值,则这会是 `undefined`
如果子进程被衍生时 `stdio[1]` 被设为任何不是 `'pipe'` 的值,则这会是 `null`

`child.stdout` `child.stdio[1]` 的一个别名。
这两个属性指向相同的值。
Expand Down
2 changes: 1 addition & 1 deletion cli/node_extra_ca_certs_file.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

当设置了此选项时,根 CA 证书(如 VeriSign)会被 `file` 指定的证书扩展。
文件应该包括一个或多个可信的 PEM 格式的证书。
如果文件丢失或格式错误,则 [`process.emitWarning()`] 会触发一个消息。
如果文件丢失或有缺陷,则 [`process.emitWarning()`] 会触发一个消息。

注意,当一个 TLS HTTPS 的客户端或服务器的 `ca` 选项的属性被显式地指定时,则指定的证书不会被使用。

7 changes: 0 additions & 7 deletions cli/node_extra_ca_certs_file_.md

This file was deleted.

6 changes: 0 additions & 6 deletions documentation/stability_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,3 @@ Node.js 的 API 仍会有少量变化,但随着发展,部分 API 会更稳
与 npm 生态系统的兼容性是一个高优先级,除非绝对必要否则不会变化。
```

```txt
稳定性: 3 - 锁定的
只接受漏洞修复、安全补丁、以及性能改进。
请不要在该特性提出修改 API 的建议,这些建议会被拒绝。
```

2 changes: 1 addition & 1 deletion errors/class_rangeerror.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

```js
require('net').connect(-1);
// 抛出 RangeError,端口应该是 > 0 && < 65536
// 抛出 "RangeError: "port" option should be >= 0 and < 65536: -1"
```

Node.js 会生成并以参数校验的形式立即抛出 `RangeError` 实例。
Expand Down
11 changes: 0 additions & 11 deletions errors/class_referenceerror.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,5 @@ doesNotExist;
// 抛出 ReferenceError,在这个程序中 doesNotExist 不是一个变量。
```

`ReferenceError` 实例有一个 `error.arguments` 属性,其值是一个只有单个元素(一个代表未定义的变量的字符串)的数组。

```js
const assert = require('assert');
try {
doesNotExist;
} catch(err) {
assert(err.arguments[0], 'doesNotExist');
}
```

除非应用程序是动态生成并运行的代码,否则 `ReferenceError` 实例应该始终被视为代码中或其依赖中的错误。

2 changes: 1 addition & 1 deletion errors/class_syntaxerror.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
```js
try {
require('vm').runInThisContext('binary ! isNotOk');
} catch(err) {
} catch (err) {
// err 是一个 SyntaxError
}
```
Expand Down
4 changes: 2 additions & 2 deletions errors/error_capturestacktrace_targetobject_constructoropt.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
```js
const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack // 类似 `new Error().stack`
myObject.stack; // 类似 `new Error().stack`
```

跟踪的第一行,不是前缀为 `ErrorType: message`,而是调用 `targetObject.toString()` 的结果。
Expand All @@ -25,6 +25,6 @@ function MyError() {
// 没传入 MyError 到 captureStackTrace,MyError 帧会显示在 .stack 属性。
// 通过传入构造函数,可以省略该帧及其之上的所有帧。
new MyError().stack
new MyError().stack;
```

2 changes: 1 addition & 1 deletion errors/error_message.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

```js
const err = new Error('错误信息');
console.log(err.message);
console.error(err.message);
// 打印: 错误信息
```

18 changes: 9 additions & 9 deletions errors/node_js_style_callbacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
const fs = require('fs');
function nodeStyleCallback(err, data) {
if (err) {
console.error('有一个错误', err);
return;
}
console.log(data);
if (err) {
console.error('There was an error', err);
return;
}
console.log(data);
}
fs.readFile('/some/file/that/does-not-exist', nodeStyleCallback);
fs.readFile('/some/file/that/does-exist', nodeStyleCallback)
fs.readFile('/some/file/that/does-exist', nodeStyleCallback);
```

JavaScript `try / catch` 机制无法用于捕获由异步 API 引起的错误。
Expand All @@ -37,14 +37,14 @@ try {
throw err;
}
});
} catch(err) {
} catch (err) {
// 这不会捕获到抛出!
console.log(err);
console.error(err);
}
```

这无法使用,因为传给 `fs.readFile()` 的回调函数是被异步地调用。
当回调被调用时,周围的代码(包括 `try { } catch(err) { }` 区域)已经退出。
当回调被调用时,周围的代码(包括 `try { } catch (err) { }` 区域)已经退出。
大多数情况下,在回调内抛出一个错误会使 Node.js 进程崩溃。
如果[]已启用,或已在 `process.on('uncaughtException')` 注册了一个句柄,则这些错误可被捕获。

6 changes: 3 additions & 3 deletions events/emitter_removelistener_eventname_listener.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ added: v0.1.26
从名为 `eventName` 的事件的监听器数组中移除指定的 `listener`

```js
var callback = (stream) => {
const callback = (stream) => {
console.log('有连接!');
};
server.on('connection', callback);
Expand All @@ -23,12 +23,12 @@ server.removeListener('connection', callback);
```js
const myEmitter = new MyEmitter();
var callbackA = () => {
const callbackA = () => {
console.log('A');
myEmitter.removeListener('event', callbackB);
};
var callbackB = () => {
const callbackB = () => {
console.log('B');
};
Expand Down
4 changes: 2 additions & 2 deletions events/error_events.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ myEmitter.emit('error', new Error('whoops!'));
const myEmitter = new MyEmitter();
process.on('uncaughtException', (err) => {
console.log('有错误');
console.error('有错误');
});
myEmitter.emit('error', new Error('whoops!'));
Expand All @@ -29,7 +29,7 @@ myEmitter.emit('error', new Error('whoops!'));
```js
const myEmitter = new MyEmitter();
myEmitter.on('error', (err) => {
console.log('有错误');
console.error('有错误');
});
myEmitter.emit('error', new Error('whoops!'));
// 打印: 有错误
Expand Down
4 changes: 2 additions & 2 deletions events/handling_events_only_once.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

```js
const myEmitter = new MyEmitter();
var m = 0;
let m = 0;
myEmitter.on('event', () => {
console.log(++m);
});
Expand All @@ -19,7 +19,7 @@ myEmitter.emit('event');

```js
const myEmitter = new MyEmitter();
var m = 0;
let m = 0;
myEmitter.once('event', () => {
console.log(++m);
});
Expand Down
6 changes: 3 additions & 3 deletions fs/class_fs_stats.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ added: v0.1.21
对于一个普通文件,[`util.inspect(stats)`] 会返回一个类似如下的字符串:

```js
{
Stats {
dev: 2114,
ino: 48064969,
mode: 33188,
Expand All @@ -29,8 +29,8 @@ added: v0.1.21
atime: Mon, 10 Oct 2011 23:24:11 GMT,
mtime: Mon, 10 Oct 2011 23:24:11 GMT,
ctime: Mon, 10 Oct 2011 23:24:11 GMT,
birthtime: Mon, 10 Oct 2011 23:24:11 GMT
}
birthtime: Mon, 10 Oct 2011 23:24:11 GMT }
```

注意,`atime``mtime``birthtime` `ctime` [`Date`] 对象的实例,比较这些对象的值需要使用适当的方法。
Expand Down
18 changes: 9 additions & 9 deletions fs/fs_access_path_mode_callback.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ fs.access('myfile', (err) => {
```js
fs.open('myfile', 'wx', (err, fd) => {
if (err) {
if (err.code === "EEXIST") {
if (err.code === 'EEXIST') {
console.error('myfile already exists');
return;
} else {
throw err;
}
throw err;
}
writeMyData(fd);
Expand All @@ -74,12 +74,12 @@ fs.open('myfile', 'wx', (err, fd) => {
```js
fs.access('myfile', (err) => {
if (err) {
if (err.code === "ENOENT") {
if (err.code === 'ENOENT') {
console.error('myfile does not exist');
return;
} else {
throw err;
}
throw err;
}
fs.open('myfile', 'r', (err, fd) => {
Expand All @@ -94,12 +94,12 @@ fs.access('myfile', (err) => {
```js
fs.open('myfile', 'r', (err, fd) => {
if (err) {
if (err.code === "ENOENT") {
if (err.code === 'ENOENT') {
console.error('myfile does not exist');
return;
} else {
throw err;
}
throw err;
}
readMyData(fd);
Expand Down
Loading

0 comments on commit a794e61

Please sign in to comment.