Açıklama Yok

test-zlib-dictionary.js 3.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 compression/decompression with dictionary
  22. var common = require('../common.js');
  23. var assert = require('assert');
  24. var zlib = require('zlib');
  25. var path = require('path');
  26. var spdyDict = new Buffer([
  27. 'optionsgetheadpostputdeletetraceacceptaccept-charsetaccept-encodingaccept-',
  28. 'languageauthorizationexpectfromhostif-modified-sinceif-matchif-none-matchi',
  29. 'f-rangeif-unmodifiedsincemax-forwardsproxy-authorizationrangerefererteuser',
  30. '-agent10010120020120220320420520630030130230330430530630740040140240340440',
  31. '5406407408409410411412413414415416417500501502503504505accept-rangesageeta',
  32. 'glocationproxy-authenticatepublicretry-afterservervarywarningwww-authentic',
  33. 'ateallowcontent-basecontent-encodingcache-controlconnectiondatetrailertran',
  34. 'sfer-encodingupgradeviawarningcontent-languagecontent-lengthcontent-locati',
  35. 'oncontent-md5content-rangecontent-typeetagexpireslast-modifiedset-cookieMo',
  36. 'ndayTuesdayWednesdayThursdayFridaySaturdaySundayJanFebMarAprMayJunJulAugSe',
  37. 'pOctNovDecchunkedtext/htmlimage/pngimage/jpgimage/gifapplication/xmlapplic',
  38. 'ation/xhtmltext/plainpublicmax-agecharset=iso-8859-1utf-8gzipdeflateHTTP/1',
  39. '.1statusversionurl\0'
  40. ].join(''));
  41. var deflate = zlib.createDeflate({ dictionary: spdyDict });
  42. var input = [
  43. 'HTTP/1.1 200 Ok',
  44. 'Server: node.js',
  45. 'Content-Length: 0',
  46. ''
  47. ].join('\r\n');
  48. var called = 0;
  49. //
  50. // We'll use clean-new inflate stream each time
  51. // and .reset() old dirty deflate one
  52. //
  53. function run(num) {
  54. var inflate = zlib.createInflate({ dictionary: spdyDict });
  55. if (num === 2) {
  56. deflate.reset();
  57. deflate.removeAllListeners('data');
  58. }
  59. // Put data into deflate stream
  60. deflate.on('data', function(chunk) {
  61. inflate.write(chunk);
  62. });
  63. // Get data from inflate stream
  64. var output = [];
  65. inflate.on('data', function(chunk) {
  66. output.push(chunk);
  67. });
  68. inflate.on('end', function() {
  69. called++;
  70. assert.equal(output.join(''), input);
  71. if (num < 2) run(num + 1);
  72. });
  73. deflate.write(input);
  74. deflate.flush(function() {
  75. inflate.end();
  76. });
  77. }
  78. run(1);
  79. process.on('exit', function() {
  80. assert.equal(called, 2);
  81. });