Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80529 views
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
22
// test convenience methods with and without options supplied
23
24
var tape = require('tape');
25
var zlib = require('../');
26
27
var expect = 'blahblahblahblahblahblah';
28
var opts = {
29
level: 9,
30
chunkSize: 1024,
31
};
32
33
[
34
['gzip', 'gunzip'],
35
['gzip', 'unzip'],
36
['deflate', 'inflate'],
37
['deflateRaw', 'inflateRaw'],
38
].forEach(function(method) {
39
tape(method.join(' '), function(t) {
40
t.plan(4);
41
42
zlib[method[0]](expect, opts, function(err, result) {
43
zlib[method[1]](result, opts, function(err, result) {
44
t.deepEqual(result, new Buffer(expect),
45
'Should get original string after ' +
46
method[0] + '/' + method[1] + ' with options.');
47
});
48
});
49
50
zlib[method[0]](expect, function(err, result) {
51
zlib[method[1]](result, function(err, result) {
52
t.deepEqual(result, new Buffer(expect),
53
'Should get original string after ' +
54
method[0] + '/' + method[1] + ' without options.');
55
});
56
});
57
58
var result = zlib[method[0] + 'Sync'](expect, opts);
59
result = zlib[method[1] + 'Sync'](result, opts);
60
t.deepEqual(result, new Buffer(expect),
61
'Should get original string after ' +
62
method[0] + '/' + method[1] + ' with options.');
63
64
result = zlib[method[0] + 'Sync'](expect);
65
result = zlib[method[1] + 'Sync'](result);
66
t.deepEqual(result, new Buffer(expect),
67
'Should get original string after ' +
68
method[0] + '/' + method[1] + ' without options.');
69
});
70
});
71
72