Нема описа

test-zlib-convenience-methods.js 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright Joyent, Inc. and other Node contributors.
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a
  4. // copy of this software and associated documentation files (the
  5. // "Software"), to deal in the Software without restriction, including
  6. // without limitation the rights to use, copy, modify, merge, publish,
  7. // distribute, sublicense, and/or sell copies of the Software, and to permit
  8. // persons to whom the Software is furnished to do so, subject to the
  9. // following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included
  12. // in all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  15. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  17. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  18. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  19. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  20. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. // test convenience methods with and without options supplied
  22. var tape = require('tape');
  23. var zlib = require('../');
  24. var expect = 'blahblahblahblahblahblah';
  25. var opts = {
  26. level: 9,
  27. chunkSize: 1024,
  28. };
  29. [
  30. ['gzip', 'gunzip'],
  31. ['gzip', 'unzip'],
  32. ['deflate', 'inflate'],
  33. ['deflateRaw', 'inflateRaw'],
  34. ].forEach(function(method) {
  35. tape(method.join(' '), function(t) {
  36. t.plan(4);
  37. zlib[method[0]](expect, opts, function(err, result) {
  38. zlib[method[1]](result, opts, function(err, result) {
  39. t.deepEqual(result, new Buffer(expect),
  40. 'Should get original string after ' +
  41. method[0] + '/' + method[1] + ' with options.');
  42. });
  43. });
  44. zlib[method[0]](expect, function(err, result) {
  45. zlib[method[1]](result, function(err, result) {
  46. t.deepEqual(result, new Buffer(expect),
  47. 'Should get original string after ' +
  48. method[0] + '/' + method[1] + ' without options.');
  49. });
  50. });
  51. var result = zlib[method[0] + 'Sync'](expect, opts);
  52. result = zlib[method[1] + 'Sync'](result, opts);
  53. t.deepEqual(result, new Buffer(expect),
  54. 'Should get original string after ' +
  55. method[0] + '/' + method[1] + ' with options.');
  56. result = zlib[method[0] + 'Sync'](expect);
  57. result = zlib[method[1] + 'Sync'](result);
  58. t.deepEqual(result, new Buffer(expect),
  59. 'Should get original string after ' +
  60. method[0] + '/' + method[1] + ' without options.');
  61. });
  62. });