Revision 8d146689 src/node_zlib.cc
src/node_zlib.cc | ||
---|---|---|
39 | 39 |
static Persistent<String> onerror_sym; |
40 | 40 |
|
41 | 41 |
enum node_zlib_mode { |
42 |
DEFLATE = 1, |
|
42 |
NONE, |
|
43 |
DEFLATE, |
|
43 | 44 |
INFLATE, |
44 | 45 |
GZIP, |
45 | 46 |
GUNZIP, |
... | ... | |
60 | 61 |
|
61 | 62 |
ZCtx(node_zlib_mode mode) : ObjectWrap(), dictionary_(NULL), mode_(mode) {} |
62 | 63 |
|
64 |
|
|
63 | 65 |
~ZCtx() { |
66 |
Clear(); |
|
67 |
} |
|
68 |
|
|
69 |
|
|
70 |
void Clear() { |
|
71 |
assert(!write_in_progress_ && "write in progress"); |
|
72 |
assert(init_done_ && "clear before init"); |
|
73 |
assert(mode_ <= UNZIP); |
|
74 |
|
|
64 | 75 |
if (mode_ == DEFLATE || mode_ == GZIP || mode_ == DEFLATERAW) { |
65 | 76 |
(void)deflateEnd(&strm_); |
66 | 77 |
} else if (mode_ == INFLATE || mode_ == GUNZIP || mode_ == INFLATERAW || |
67 | 78 |
mode_ == UNZIP) { |
68 | 79 |
(void)inflateEnd(&strm_); |
69 | 80 |
} |
81 |
mode_ = NONE; |
|
82 |
|
|
83 |
if (dictionary_ != NULL) { |
|
84 |
delete[] dictionary_; |
|
85 |
dictionary_ = NULL; |
|
86 |
} |
|
87 |
} |
|
88 |
|
|
70 | 89 |
|
71 |
if (dictionary_ != NULL) delete[] dictionary_; |
|
90 |
static Handle<Value> Clear(const Arguments& args) { |
|
91 |
HandleScope scope; |
|
92 |
ZCtx *ctx = ObjectWrap::Unwrap<ZCtx>(args.This()); |
|
93 |
ctx->Clear(); |
|
94 |
return scope.Close(Undefined()); |
|
72 | 95 |
} |
73 | 96 |
|
97 |
|
|
74 | 98 |
// write(flush, in, in_off, in_len, out, out_off, out_len) |
75 | 99 |
static Handle<Value> Write(const Arguments& args) { |
76 | 100 |
HandleScope scope; |
... | ... | |
78 | 102 |
|
79 | 103 |
ZCtx *ctx = ObjectWrap::Unwrap<ZCtx>(args.This()); |
80 | 104 |
assert(ctx->init_done_ && "write before init"); |
105 |
assert(ctx->mode_ != NONE && "already finalized"); |
|
81 | 106 |
|
82 | 107 |
assert(!ctx->write_in_progress_ && "write already in progress"); |
83 | 108 |
ctx->write_in_progress_ = true; |
... | ... | |
450 | 475 |
|
451 | 476 |
NODE_SET_PROTOTYPE_METHOD(z, "write", ZCtx::Write); |
452 | 477 |
NODE_SET_PROTOTYPE_METHOD(z, "init", ZCtx::Init); |
478 |
NODE_SET_PROTOTYPE_METHOD(z, "clear", ZCtx::Clear); |
|
453 | 479 |
NODE_SET_PROTOTYPE_METHOD(z, "reset", ZCtx::Reset); |
454 | 480 |
|
455 | 481 |
z->SetClassName(String::NewSymbol("Zlib")); |
Also available in: Unified diff