/
data_reader_read.js
39 lines (36 loc) · 1.09 KB
/
data_reader_read.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 DataReader = require ("../lib").DataReader;
var file = "data_reader_file";
var encoding = "utf8";
new DataReader (file, { encoding: encoding, bufferSize: 5 })
//This event is emitted on error, the file is closed automatically
.on ("error", function (error){
console.log (error);
})
//This event is only emitted when the encoding is unspecified
.on ("byte", function (b, byteOffset){
console.log ("byte:\t\t" + b);
})
//This event is only emitted when the encoding is specified
.on ("character", function (c, byteOffset){
console.log ("character:\t" + c);
})
//This event is only emitted when the encoding is specified
.on ("line", function (line, byteOffset){
console.log ("line:\t\t" + line);
if (line === "Lorem"){
this.pause ();
var me = this;
setTimeout (function (){
me.resume ();
}, 3000);
}
})
//This event is emitted always
.on ("buffer", function (buffer, byteOffset){
console.log (encoding ? "buffer:\t\t" + buffer : buffer);
})
//This event is emitted always
.on ("end", function (){
console.log ("END");
})
.read ();