forked from nodejscn/node-api-cn
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew_buffer_string_encoding.md
More file actions
37 lines (26 loc) · 1.01 KB
/
new_buffer_string_encoding.md
File metadata and controls
37 lines (26 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<!-- YAML
deprecated: v6.0.0
changes:
- version: v7.2.1
pr-url: https://github.com/nodejs/node/pull/9529
description: Calling this constructor no longer emits a deprecation warning.
- version: v7.0.0
pr-url: https://github.com/nodejs/node/pull/8169
description: Calling this constructor emits a deprecation warning now.
-->
> 稳定性: 0 - 废弃的: 使用 [`Buffer.from(string[, encoding])`][`Buffer.from(string)`] 代替。
* `string` {string} String to encode
* `encoding` {string} The encoding of `string`. **Default:** `'utf8'`
Creates a new `Buffer` containing the given JavaScript string `string`. If
provided, the `encoding` parameter identifies the character encoding of `string`.
Examples:
```js
const buf1 = new Buffer('this is a tést');
// Prints: this is a tést
console.log(buf1.toString());
// Prints: this is a tC)st
console.log(buf1.toString('ascii'));
const buf2 = new Buffer('7468697320697320612074c3a97374', 'hex');
// Prints: this is a tést
console.log(buf2.toString());
```