您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. var pump = require('./index')
  2. var rs = require('fs').createReadStream('/dev/random')
  3. var ws = require('fs').createWriteStream('/dev/null')
  4. var toHex = function () {
  5. var reverse = new (require('stream').Transform)()
  6. reverse._transform = function (chunk, enc, callback) {
  7. reverse.push(chunk.toString('hex'))
  8. callback()
  9. }
  10. return reverse
  11. }
  12. var wsClosed = false
  13. var rsClosed = false
  14. var callbackCalled = false
  15. var check = function () {
  16. if (wsClosed && rsClosed && callbackCalled) {
  17. console.log('test-node.js passes')
  18. clearTimeout(timeout)
  19. }
  20. }
  21. ws.on('close', function () {
  22. wsClosed = true
  23. check()
  24. })
  25. rs.on('close', function () {
  26. rsClosed = true
  27. check()
  28. })
  29. var res = pump(rs, toHex(), toHex(), toHex(), ws, function () {
  30. callbackCalled = true
  31. check()
  32. })
  33. if (res !== ws) {
  34. throw new Error('should return last stream')
  35. }
  36. setTimeout(function () {
  37. rs.destroy()
  38. }, 1000)
  39. var timeout = setTimeout(function () {
  40. throw new Error('timeout')
  41. }, 5000)