Last change
on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
992 bytes
|
Line | |
---|
1 | var pump = require('./index')
|
---|
2 |
|
---|
3 | var rs = require('fs').createReadStream('/dev/random')
|
---|
4 | var ws = require('fs').createWriteStream('/dev/null')
|
---|
5 |
|
---|
6 | var toHex = function () {
|
---|
7 | var reverse = new (require('stream').Transform)()
|
---|
8 |
|
---|
9 | reverse._transform = function (chunk, enc, callback) {
|
---|
10 | reverse.push(chunk.toString('hex'))
|
---|
11 | callback()
|
---|
12 | }
|
---|
13 |
|
---|
14 | return reverse
|
---|
15 | }
|
---|
16 |
|
---|
17 | var wsClosed = false
|
---|
18 | var rsClosed = false
|
---|
19 | var callbackCalled = false
|
---|
20 |
|
---|
21 | var check = function () {
|
---|
22 | if (wsClosed && rsClosed && callbackCalled) {
|
---|
23 | console.log('test-node.js passes')
|
---|
24 | clearTimeout(timeout)
|
---|
25 | }
|
---|
26 | }
|
---|
27 |
|
---|
28 | ws.on('close', function () {
|
---|
29 | wsClosed = true
|
---|
30 | check()
|
---|
31 | })
|
---|
32 |
|
---|
33 | rs.on('close', function () {
|
---|
34 | rsClosed = true
|
---|
35 | check()
|
---|
36 | })
|
---|
37 |
|
---|
38 | var res = pump(rs, toHex(), toHex(), toHex(), ws, function () {
|
---|
39 | callbackCalled = true
|
---|
40 | check()
|
---|
41 | })
|
---|
42 |
|
---|
43 | if (res !== ws) {
|
---|
44 | throw new Error('should return last stream')
|
---|
45 | }
|
---|
46 |
|
---|
47 | setTimeout(function () {
|
---|
48 | rs.destroy()
|
---|
49 | }, 1000)
|
---|
50 |
|
---|
51 | var timeout = setTimeout(function () {
|
---|
52 | throw new Error('timeout')
|
---|
53 | }, 5000)
|
---|
Note:
See
TracBrowser
for help on using the repository browser.