-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
27 lines (24 loc) · 847 Bytes
/
test.js
File metadata and controls
27 lines (24 loc) · 847 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
/* TEST FILE - Copyright (c) 2017 bytes-stream - Tanase Laurentiu Iulian - https://github.com/RealTimeCom/bytes-stream */
'use strict';
const bytes = 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;
}
};
let s = Buffer.from('0123456789');
(new read(3, s)).pipe(new bytes([1, 5])).
on('data', d => console.log('data', d.toString())).
on('end', () => console.log('end'));