test.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. var tape = require('tape')
  2. var zlib = require('zlib')
  3. var concat = require('concat-stream')
  4. var fs = require('fs')
  5. var gunzip = require('./')
  6. tape('deflated input', function (t) {
  7. fs.createReadStream(__filename)
  8. .pipe(zlib.createDeflate())
  9. .pipe(gunzip())
  10. .pipe(concat(function (data) {
  11. t.same(data, fs.readFileSync(__filename))
  12. t.end()
  13. }))
  14. })
  15. tape('deflated multiple times', function (t) {
  16. fs.createReadStream(__filename)
  17. .pipe(zlib.createDeflate())
  18. .pipe(zlib.createDeflate())
  19. .pipe(gunzip())
  20. .pipe(concat(function (data) {
  21. t.same(data, fs.readFileSync(__filename))
  22. t.end()
  23. }))
  24. })
  25. tape('gunzipped input', function (t) {
  26. fs.createReadStream(__filename)
  27. .pipe(zlib.createGzip())
  28. .pipe(gunzip())
  29. .pipe(concat(function (data) {
  30. t.same(data, fs.readFileSync(__filename))
  31. t.end()
  32. }))
  33. })
  34. tape('gunzipped multiple times', function (t) {
  35. fs.createReadStream(__filename)
  36. .pipe(zlib.createGzip())
  37. .pipe(zlib.createGzip())
  38. .pipe(gunzip())
  39. .pipe(concat(function (data) {
  40. t.same(data, fs.readFileSync(__filename))
  41. t.end()
  42. }))
  43. })
  44. tape('regular input', function (t) {
  45. fs.createReadStream(__filename)
  46. .pipe(gunzip())
  47. .pipe(concat(function (data) {
  48. t.same(data, fs.readFileSync(__filename))
  49. t.end()
  50. }))
  51. })
  52. tape('limited recursion', function (t) {
  53. t.plan(1)
  54. fs.createReadStream(__filename)
  55. .pipe(zlib.createGzip())
  56. .pipe(zlib.createGzip())
  57. .pipe(gunzip(1))
  58. .on('finish', function () {
  59. t.fail('should not finish')
  60. })
  61. .on('error', function (err) {
  62. t.same(err.message, 'Maximum recursion reached')
  63. })
  64. })