Skip to content

Commit aa2d930

Browse files
committed
Wrap zlib transforms
1 parent e97b6ea commit aa2d930

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

bootstrap.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ if (fs.lchmod) wrap(fs, 'lchmod', activator);
121121
// only wrap ftruncate in versions of node that have it
122122
if (fs.ftruncate) wrap(fs, 'ftruncate', activator);
123123

124+
// Wrap zlib streams
125+
var zProto = Object.getPrototypeOf(require('zlib').Deflate.prototype);
126+
wrap(zProto, "_transform", activator);
127+
128+
124129
////////////////////////////////////////////////////////////////////////////////
125130

126131
// Polyfilled version of process.addAsyncListener

test/zlib.tap.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
if (!process.addAsyncListener) require('../bootstrap.js');
3+
4+
var tap = require('tap')
5+
, test = tap.test
6+
, createNamespace = require('continuation-local-storage').createNamespace
7+
;
8+
9+
var zlib = require('zlib');
10+
11+
test("continuation-local state with zlib", function (t) {
12+
t.plan(1);
13+
14+
var namespace = createNamespace('namespace');
15+
namespace.set('test', 0xabad1dea);
16+
17+
t.test("deflate", function (t) {
18+
namespace.run(function () {
19+
namespace.set('test', 42);
20+
zlib.deflate(new Buffer("Goodbye World"), function (err, deflated) {
21+
if (err) throw err;
22+
t.equal(namespace.get('test'), 42, "mutated state was preserved");
23+
t.end();
24+
});
25+
});
26+
});
27+
});

0 commit comments

Comments
 (0)