Lines Matching refs:pt
54 const pt = new PassThrough();
56 pt.write(Buffer.from('foog'));
57 pt.write(Buffer.from('bark'));
58 pt.write(Buffer.from('bazy'));
59 pt.write(Buffer.from('kuel'));
60 pt.end();
62 assert.strictEqual(pt.read(5).toString(), 'foogb');
63 assert.strictEqual(pt.read(5).toString(), 'arkba');
64 assert.strictEqual(pt.read(5).toString(), 'zykue');
65 assert.strictEqual(pt.read(5).toString(), 'l');
70 const pt = new PassThrough({ objectMode: true });
72 pt.write(1);
73 pt.write(true);
74 pt.write(false);
75 pt.write(0);
76 pt.write('foo');
77 pt.write('');
78 pt.write({ a: 'b' });
79 pt.end();
81 assert.strictEqual(pt.read(), 1);
82 assert.strictEqual(pt.read(), true);
83 assert.strictEqual(pt.read(), false);
84 assert.strictEqual(pt.read(), 0);
85 assert.strictEqual(pt.read(), 'foo');
86 assert.strictEqual(pt.read(), '');
87 assert.deepStrictEqual(pt.read(), { a: 'b' });
92 const pt = PassThrough();
94 assert(pt instanceof PassThrough);
99 const pt = Transform();
101 assert(pt instanceof Transform);
106 const pt = new Transform();
107 pt._transform = function(c, e, cb) {
109 pt.push(ret);
113 pt.write(Buffer.from('foog'));
114 pt.write(Buffer.from('bark'));
115 pt.write(Buffer.from('bazy'));
116 pt.write(Buffer.from('kuel'));
117 pt.end();
119 assert.strictEqual(pt.read(5).toString(), 'xxxxx');
120 assert.strictEqual(pt.read(5).toString(), 'xxxxx');
121 assert.strictEqual(pt.read(5).toString(), 'xxxxx');
122 assert.strictEqual(pt.read(5).toString(), 'x');
127 const pt = new Transform({ objectMode: true });
128 pt._transform = function(c, e, cb) {
129 pt.push(JSON.stringify(c));
133 pt.write(1);
134 pt.write(true);
135 pt.write(false);
136 pt.write(0);
137 pt.write('foo');
138 pt.write('');
139 pt.write({ a: 'b' });
140 pt.end();
142 assert.strictEqual(pt.read(), '1');
143 assert.strictEqual(pt.read(), 'true');
144 assert.strictEqual(pt.read(), 'false');
145 assert.strictEqual(pt.read(), '0');
146 assert.strictEqual(pt.read(), '"foo"');
147 assert.strictEqual(pt.read(), '""');
148 assert.strictEqual(pt.read(), '{"a":"b"}');
153 const pt = new Transform();
154 pt._transform = function(chunk, encoding, cb) {
156 pt.push(chunk);
161 pt.write(Buffer.from('foog'));
162 pt.write(Buffer.from('bark'));
163 pt.write(Buffer.from('bazy'));
164 pt.write(Buffer.from('kuel'));
165 pt.end();
167 pt.on('finish', common.mustCall(function() {
168 assert.strictEqual(pt.read(5).toString(), 'foogb');
169 assert.strictEqual(pt.read(5).toString(), 'arkba');
170 assert.strictEqual(pt.read(5).toString(), 'zykue');
171 assert.strictEqual(pt.read(5).toString(), 'l');
177 const pt = new Transform();
180 pt._transform = function(chunk, encoding, cb) {
182 pt.push(chunk);
184 pt.push(chunk);
190 pt.write(Buffer.from('foog'));
191 pt.write(Buffer.from('bark'));
192 pt.write(Buffer.from('bazy'));
193 pt.write(Buffer.from('kuel'));
194 pt.end();
196 pt.on('finish', common.mustCall(function() {
197 assert.strictEqual(pt.read(5).toString(), 'foogf');
198 assert.strictEqual(pt.read(5).toString(), 'oogba');
199 assert.strictEqual(pt.read(5).toString(), 'rkbar');
200 assert.strictEqual(pt.read(5).toString(), 'kbazy');
201 assert.strictEqual(pt.read(5).toString(), 'bazyk');
202 assert.strictEqual(pt.read(5).toString(), 'uelku');
203 assert.strictEqual(pt.read(5).toString(), 'el');
209 const pt = new Transform();
213 pt.state = '';
215 pt._transform = function(chunk, encoding, cb) {
222 pt.push(Buffer.from(this.state));
229 pt._flush = function(cb) {
231 pt.push(Buffer.from(this.state));
236 pt.write(Buffer.from('aaaa'));
237 pt.write(Buffer.from('bbbb'));
238 pt.write(Buffer.from('cccc'));
239 pt.write(Buffer.from('dddd'));
240 pt.write(Buffer.from('eeee'));
241 pt.write(Buffer.from('aaaa'));
242 pt.write(Buffer.from('bbbb'));
243 pt.write(Buffer.from('cccc'));
244 pt.write(Buffer.from('dddd'));
245 pt.write(Buffer.from('eeee'));
246 pt.write(Buffer.from('aaaa'));
247 pt.write(Buffer.from('bbbb'));
248 pt.write(Buffer.from('cccc'));
249 pt.write(Buffer.from('dddd'));
250 pt.end();
253 pt.on('finish', common.mustCall(function() {
254 assert.strictEqual(pt.read(5).toString(), 'abcde');
255 assert.strictEqual(pt.read(5).toString(), 'abcde');
256 assert.strictEqual(pt.read(5).toString(), 'abcd');
266 const pt = new Transform({ highWaterMark: 3 });
267 pt._transform = function(c, e, cb) {
272 pt.push(saved);
275 pt.push(c);
281 pt.once('readable', function() {
283 pt.write(Buffer.from('d'));
284 pt.write(Buffer.from('ef'), common.mustCall(function() {
285 pt.end();
287 assert.strictEqual(pt.read().toString(), 'abcdef');
288 assert.strictEqual(pt.read(), null);
292 pt.write(Buffer.from('abc'));
298 const pt = new PassThrough();
300 pt.on('readable', function() {
304 pt.write(Buffer.from('foog'));
305 pt.write(Buffer.from('bark'));
308 assert.strictEqual(pt.read(5).toString(), 'foogb');
309 assert.strictEqual(String(pt.read(5)), 'null');
312 pt.write(Buffer.from('bazy'));
313 pt.write(Buffer.from('kuel'));
316 assert.strictEqual(pt.read(5).toString(), 'arkba');
317 assert.strictEqual(pt.read(5).toString(), 'zykue');
318 assert.strictEqual(pt.read(5), null);
320 pt.end();
323 assert.strictEqual(pt.read(5).toString(), 'l');
324 assert.strictEqual(pt.read(5), null);
330 const pt = new PassThrough();
332 pt.on('readable', function() {
336 pt.write(Buffer.from('foog'));
337 pt.write(Buffer.from('bark'));
340 assert.strictEqual(pt.read(5).toString(), 'foogb');
341 assert.strictEqual(pt.read(5), null);
343 pt.once('readable', common.mustCall(function() {
344 assert.strictEqual(pt.read(5).toString(), 'arkba');
345 assert.strictEqual(pt.read(5), null);
347 pt.once('readable', common.mustCall(function() {
348 assert.strictEqual(pt.read(5).toString(), 'zykue');
349 assert.strictEqual(pt.read(5), null);
350 pt.once('readable', common.mustCall(function() {
351 assert.strictEqual(pt.read(5).toString(), 'l');
352 assert.strictEqual(pt.read(5), null);
355 pt.end();
357 pt.write(Buffer.from('kuel'));
360 pt.write(Buffer.from('bazy'));
365 const pt = new PassThrough();
367 pt.on('data', function(chunk) {
371 pt.on('end', common.mustCall(function() {
375 pt.write(Buffer.from('foog'));
377 pt.write(Buffer.from('bark'));
379 pt.write(Buffer.from('bazy'));
381 pt.write(Buffer.from('kuel'));
383 pt.end();