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