-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
39 lines (38 loc) · 1.14 KB
/
test.js
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
37
38
39
// var fs = require('fs');
// fs.open(
// 'info.txt', 'r',
// function (err, handle) { // we'll see more about the err param in a bit
// var buf = new Buffer(100000);
// fs.read(
// handle, buf, 0, 100000, null,
// function (err, length) {
// console.log(buf.toString('utf8', 0, length));
// fs.close(handle, function () { /* don't care */ });
// }
// );
// }
// );
var fs = require('fs');
fs.open(
'info.txt', 'r',
function (err, handle) {
if (err) {
console.log("ERROR: " + err.code
+ " (" + err.message + ")");
return;
}
var buf = new Buffer(100000);
fs.read(
handle, buf, 0, 100000, null,
function (err, length) {
if (err) {
console.log("ERROR: " + err.code +
" (" + err.message + ")");
return;
}
console.log(buf.toString('utf8', 0, length));
fs.close(handle, function () { /* don't care */ });
}
);
}
);