forked from visionmedia/masteringnode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamples.js
More file actions
30 lines (23 loc) · 813 Bytes
/
examples.js
File metadata and controls
30 lines (23 loc) · 813 Bytes
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
var hello = new Buffer('Hello');
console.log(hello);
console.log(hello.toString());
var hello = new Buffer([0x48, 0x65, 0x6c, 0x6c, 0x6f]);
console.log(hello);
console.log(hello.toString());
var hello = new Buffer([0x48, 0x65, 0x6c, 0x6c, 0x6f]);
console.log(hello);
console.log(hello.toString());
var ellipsis = new Buffer('…');
console.log('… string length: %d', '…'.length);
console.log('… byte length: %d', ellipsis.length);
console.log('… byte length: %d', Buffer.byteLength('…'));
console.log(ellipsis);
var buf = new Buffer(5);
buf.write('he');
buf.write('l', 2);
buf.write('lo', 3);
console.log(buf.toString());
console.log(new Buffer('…', 'ascii').toString());
var buf = new Buffer('just some data');
console.log(buf.slice(4, 9).toString());
console.log(buf.toString('ascii', 4, 9));