-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.js
More file actions
29 lines (26 loc) · 869 Bytes
/
test.js
File metadata and controls
29 lines (26 loc) · 869 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
/* TEST FILE - Copyright (c) 2017 chunks-stream - Tanase Laurentiu Iulian - https://github.com/RealTimeCom/chunks-stream */
'use strict';
const chunks = require('./index.js'),
Readable = require('stream').Readable;
class read extends Readable {
constructor(s, r) {
super();
this.r = r; // buffer source
this.s = s; // read size
this.p = 0; // current pointer
this.l = this.r.length;
}
}
read.prototype._read = function(size) {
if (this.p < this.l) {
//console.log('read', this.r.slice(this.p, this.p + this.s).toString());
this.push(this.r.slice(this.p, this.p + this.s));
this.p += this.s;
}else{
this.push(null);
}
};
(new read(3, Buffer.from('0123456789'))).
pipe(new chunks(2)).
on('data', d => console.log('data', d.toString())).
on('end', () => console.log('end'));