Skip to content
This repository
Newer
Older
100644 495 lines (390 sloc) 13.924 kb
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
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
ff4a9d38 »
2012-03-10 core: use proper #include directives
23 #include "v8.h"
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
24 #include <errno.h>
25 #include <string.h>
26 #include <stdlib.h>
27 #include <sys/types.h>
28
531eba18 »
2012-03-12 zlib: fix include of zlib.h
29 #include "zlib.h"
ff4a9d38 »
2012-03-10 core: use proper #include directives
30 #include "node.h"
31 #include "node_buffer.h"
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
32
33
34 namespace node {
35 using namespace v8;
36
37
74a8215a »
2012-02-03 Revert support for isolates.
38 static Persistent<String> callback_sym;
01d46f3a »
2012-03-31 Fix #3052 Handle errors properly in zlib
39 static Persistent<String> onerror_sym;
74a8215a »
2012-02-03 Revert support for isolates.
40
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
41 enum node_zlib_mode {
42 DEFLATE = 1,
43 INFLATE,
44 GZIP,
45 GUNZIP,
46 DEFLATERAW,
47 INFLATERAW,
48 UNZIP
49 };
50
51
52 void InitZlib(v8::Handle<v8::Object> target);
53
54
55 /**
56 * Deflate/Inflate
57 */
44eb279e »
2012-03-21 zlib: don't use C++ templates
58 class ZCtx : public ObjectWrap {
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
59 public:
60
44eb279e »
2012-03-21 zlib: don't use C++ templates
61 ZCtx(node_zlib_mode mode) : ObjectWrap(), dictionary_(NULL), mode_(mode) {}
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
62
63 ~ZCtx() {
44eb279e »
2012-03-21 zlib: don't use C++ templates
64 if (mode_ == DEFLATE || mode_ == GZIP || mode_ == DEFLATERAW) {
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
65 (void)deflateEnd(&strm_);
bf539f9b »
2012-07-08 zlib: Call inflateEnd for UNZIP. Fixes memory leak.
66 } else if (mode_ == INFLATE || mode_ == GUNZIP || mode_ == INFLATERAW ||
67 mode_ == UNZIP) {
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
68 (void)inflateEnd(&strm_);
69 }
e6091952 »
2011-12-02 [zlib] added dictionary support
70
71 if (dictionary_ != NULL) delete[] dictionary_;
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
72 }
73
74 // write(flush, in, in_off, in_len, out, out_off, out_len)
07701e7c »
2012-01-11 zlib: C++ style fixes
75 static Handle<Value> Write(const Arguments& args) {
d104bfd5 »
2011-09-17 zlib: Fix test so that it's not trivially passing, then pass it.
76 HandleScope scope;
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
77 assert(args.Length() == 7);
78
44eb279e »
2012-03-21 zlib: don't use C++ templates
79 ZCtx *ctx = ObjectWrap::Unwrap<ZCtx>(args.This());
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
80 assert(ctx->init_done_ && "write before init");
81
8cca30f3 »
2012-01-10 zlib binding cleanup
82 assert(!ctx->write_in_progress_ && "write already in progress");
83 ctx->write_in_progress_ = true;
84
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
85 unsigned int flush = args[0]->Uint32Value();
86 Bytef *in;
87 Bytef *out;
88 size_t in_off, in_len, out_off, out_len;
89
90 if (args[1]->IsNull()) {
91 // just a flush
92 Bytef nada[1] = { 0 };
93 in = nada;
94 in_len = 0;
95 in_off = 0;
96 } else {
97 assert(Buffer::HasInstance(args[1]));
98 Local<Object> in_buf;
99 in_buf = args[1]->ToObject();
07701e7c »
2012-01-11 zlib: C++ style fixes
100 in_off = args[2]->Uint32Value();
101 in_len = args[3]->Uint32Value();
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
102
103 assert(in_off + in_len <= Buffer::Length(in_buf));
104 in = reinterpret_cast<Bytef *>(Buffer::Data(in_buf) + in_off);
105 }
106
107 assert(Buffer::HasInstance(args[4]));
108 Local<Object> out_buf = args[4]->ToObject();
07701e7c »
2012-01-11 zlib: C++ style fixes
109 out_off = args[5]->Uint32Value();
110 out_len = args[6]->Uint32Value();
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
111 assert(out_off + out_len <= Buffer::Length(out_buf));
112 out = reinterpret_cast<Bytef *>(Buffer::Data(out_buf) + out_off);
113
8cca30f3 »
2012-01-10 zlib binding cleanup
114 // build up the work request
115 uv_work_t* work_req = &(ctx->work_req_);
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
116
117 ctx->strm_.avail_in = in_len;
07701e7c »
2012-01-11 zlib: C++ style fixes
118 ctx->strm_.next_in = in;
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
119 ctx->strm_.avail_out = out_len;
120 ctx->strm_.next_out = out;
121 ctx->flush_ = flush;
122
123 // set this so that later on, I can easily tell how much was written.
124 ctx->chunk_size_ = out_len;
125
74a8215a »
2012-02-03 Revert support for isolates.
126 uv_queue_work(uv_default_loop(),
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
127 work_req,
44eb279e »
2012-03-21 zlib: don't use C++ templates
128 ZCtx::Process,
129 ZCtx::After);
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
130
0ad2717f »
2012-01-10 Make sure that zlib contexts are not garbage collected when busy
131 ctx->Ref();
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
132
8cca30f3 »
2012-01-10 zlib binding cleanup
133 return ctx->handle_;
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
134 }
135
136
137 // thread pool!
138 // This function may be called multiple times on the uv_work pool
139 // for a single write() call, until all of the input bytes have
140 // been consumed.
07701e7c »
2012-01-11 zlib: C++ style fixes
141 static void Process(uv_work_t* work_req) {
44eb279e »
2012-03-21 zlib: don't use C++ templates
142 ZCtx *ctx = container_of(work_req, ZCtx, work_req_);
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
143
144 // If the avail_out is left at 0, then it means that it ran out
145 // of room. If there was avail_out left over, then it means
146 // that all of the input was consumed.
44eb279e »
2012-03-21 zlib: don't use C++ templates
147 switch (ctx->mode_) {
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
148 case DEFLATE:
149 case GZIP:
150 case DEFLATERAW:
01d46f3a »
2012-03-31 Fix #3052 Handle errors properly in zlib
151 ctx->err_ = deflate(&ctx->strm_, ctx->flush_);
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
152 break;
153 case UNZIP:
154 case INFLATE:
155 case GUNZIP:
156 case INFLATERAW:
01d46f3a »
2012-03-31 Fix #3052 Handle errors properly in zlib
157 ctx->err_ = inflate(&ctx->strm_, ctx->flush_);
e6091952 »
2011-12-02 [zlib] added dictionary support
158
159 // If data was encoded with dictionary
01d46f3a »
2012-03-31 Fix #3052 Handle errors properly in zlib
160 if (ctx->err_ == Z_NEED_DICT) {
e6091952 »
2011-12-02 [zlib] added dictionary support
161 assert(ctx->dictionary_ != NULL && "Stream has no dictionary");
01d46f3a »
2012-03-31 Fix #3052 Handle errors properly in zlib
162 if (ctx->dictionary_ != NULL) {
163
164 // Load it
165 ctx->err_ = inflateSetDictionary(&ctx->strm_,
166 ctx->dictionary_,
167 ctx->dictionary_len_);
168 assert(ctx->err_ == Z_OK && "Failed to set dictionary");
169 if (ctx->err_ == Z_OK) {
170
171 // And try to decode again
172 ctx->err_ = inflate(&ctx->strm_, ctx->flush_);
173 }
174 }
e6091952 »
2011-12-02 [zlib] added dictionary support
175 }
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
176 break;
177 default:
178 assert(0 && "wtf?");
179 }
01d46f3a »
2012-03-31 Fix #3052 Handle errors properly in zlib
180
181 // pass any errors back to the main thread to deal with.
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
182
183 // now After will emit the output, and
184 // either schedule another call to Process,
185 // or shift the queue and call Process.
186 }
187
188 // v8 land!
07701e7c »
2012-01-11 zlib: C++ style fixes
189 static void After(uv_work_t* work_req) {
d104bfd5 »
2011-09-17 zlib: Fix test so that it's not trivially passing, then pass it.
190 HandleScope scope;
44eb279e »
2012-03-21 zlib: don't use C++ templates
191 ZCtx *ctx = container_of(work_req, ZCtx, work_req_);
07701e7c »
2012-01-11 zlib: C++ style fixes
192
01d46f3a »
2012-03-31 Fix #3052 Handle errors properly in zlib
193 // Acceptable error states depend on the type of zlib stream.
194 switch (ctx->err_) {
195 case Z_OK:
196 case Z_STREAM_END:
197 case Z_BUF_ERROR:
198 // normal statuses, not fatal
199 break;
200 default:
201 // something else.
202 ZCtx::Error(ctx, "Zlib error");
203 return;
204 }
205
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
206 Local<Integer> avail_out = Integer::New(ctx->strm_.avail_out);
207 Local<Integer> avail_in = Integer::New(ctx->strm_.avail_in);
208
8cca30f3 »
2012-01-10 zlib binding cleanup
209 ctx->write_in_progress_ = false;
210
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
211 // call the write() cb
8cca30f3 »
2012-01-10 zlib binding cleanup
212 assert(ctx->handle_->Get(callback_sym)->IsFunction() &&
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
213 "Invalid callback");
214 Local<Value> args[2] = { avail_in, avail_out };
a26bee8f »
2012-04-12 MakeCallback: Consistent symbol usage
215 MakeCallback(ctx->handle_, callback_sym, ARRAY_SIZE(args), args);
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
216
0ad2717f »
2012-01-10 Make sure that zlib contexts are not garbage collected when busy
217 ctx->Unref();
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
218 }
219
01d46f3a »
2012-03-31 Fix #3052 Handle errors properly in zlib
220 static void Error(ZCtx *ctx, const char *msg_) {
221 const char *msg;
222 if (ctx->strm_.msg != NULL) {
223 msg = ctx->strm_.msg;
224 } else {
225 msg = msg_;
226 }
227
228 assert(ctx->handle_->Get(onerror_sym)->IsFunction() &&
229 "Invalid error handler");
230 HandleScope scope;
231 Local<Value> args[2] = { String::New(msg),
232 Local<Value>::New(Number::New(ctx->err_)) };
a26bee8f »
2012-04-12 MakeCallback: Consistent symbol usage
233 MakeCallback(ctx->handle_, onerror_sym, ARRAY_SIZE(args), args);
01d46f3a »
2012-03-31 Fix #3052 Handle errors properly in zlib
234
235 // no hope of rescue.
236 ctx->Unref();
237 }
238
07701e7c »
2012-01-11 zlib: C++ style fixes
239 static Handle<Value> New(const Arguments& args) {
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
240 HandleScope scope;
44eb279e »
2012-03-21 zlib: don't use C++ templates
241 if (args.Length() < 1 || !args[0]->IsInt32()) {
242 return ThrowException(Exception::TypeError(String::New("Bad argument")));
243 }
244 node_zlib_mode mode = (node_zlib_mode) args[0]->Int32Value();
245
246 if (mode < DEFLATE || mode > UNZIP) {
247 return ThrowException(Exception::TypeError(String::New("Bad argument")));
248 }
249
250 ZCtx *ctx = new ZCtx(mode);
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
251 ctx->Wrap(args.This());
252 return args.This();
253 }
254
255 // just pull the ints out of the args and call the other Init
07701e7c »
2012-01-11 zlib: C++ style fixes
256 static Handle<Value> Init(const Arguments& args) {
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
257 HandleScope scope;
258
e6091952 »
2011-12-02 [zlib] added dictionary support
259 assert((args.Length() == 4 || args.Length() == 5) &&
260 "init(windowBits, level, memLevel, strategy, [dictionary])");
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
261
44eb279e »
2012-03-21 zlib: don't use C++ templates
262 ZCtx *ctx = ObjectWrap::Unwrap<ZCtx>(args.This());
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
263
264 int windowBits = args[0]->Uint32Value();
265 assert((windowBits >= 8 && windowBits <= 15) && "invalid windowBits");
266
267 int level = args[1]->Uint32Value();
268 assert((level >= -1 && level <= 9) && "invalid compression level");
269
270 int memLevel = args[2]->Uint32Value();
271 assert((memLevel >= 1 && memLevel <= 9) && "invalid memlevel");
272
273 int strategy = args[3]->Uint32Value();
274 assert((strategy == Z_FILTERED ||
275 strategy == Z_HUFFMAN_ONLY ||
276 strategy == Z_RLE ||
277 strategy == Z_FIXED ||
278 strategy == Z_DEFAULT_STRATEGY) && "invalid strategy");
279
e6091952 »
2011-12-02 [zlib] added dictionary support
280 char* dictionary = NULL;
281 size_t dictionary_len = 0;
282 if (args.Length() >= 5 && Buffer::HasInstance(args[4])) {
283 Local<Object> dictionary_ = args[4]->ToObject();
284
285 dictionary_len = Buffer::Length(dictionary_);
286 dictionary = new char[dictionary_len];
287
288 memcpy(dictionary, Buffer::Data(dictionary_), dictionary_len);
289 }
290
291 Init(ctx, level, windowBits, memLevel, strategy,
292 dictionary, dictionary_len);
71ae1753 »
2012-01-12 zlib: reset() method for deflate/inflate streams
293 SetDictionary(ctx);
294 return Undefined();
295 }
296
297 static Handle<Value> Reset(const Arguments &args) {
298 HandleScope scope;
299
44eb279e »
2012-03-21 zlib: don't use C++ templates
300 ZCtx *ctx = ObjectWrap::Unwrap<ZCtx>(args.This());
71ae1753 »
2012-01-12 zlib: reset() method for deflate/inflate streams
301
302 Reset(ctx);
303 SetDictionary(ctx);
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
304 return Undefined();
305 }
306
07701e7c »
2012-01-11 zlib: C++ style fixes
307 static void Init(ZCtx *ctx, int level, int windowBits, int memLevel,
9e6957b0 »
2012-01-12 Merge branch 'v0.6'
308 int strategy, char* dictionary, size_t dictionary_len) {
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
309 ctx->level_ = level;
310 ctx->windowBits_ = windowBits;
311 ctx->memLevel_ = memLevel;
312 ctx->strategy_ = strategy;
313
314 ctx->strm_.zalloc = Z_NULL;
315 ctx->strm_.zfree = Z_NULL;
316 ctx->strm_.opaque = Z_NULL;
317
318 ctx->flush_ = Z_NO_FLUSH;
319
01d46f3a »
2012-03-31 Fix #3052 Handle errors properly in zlib
320 ctx->err_ = Z_OK;
321
44eb279e »
2012-03-21 zlib: don't use C++ templates
322 if (ctx->mode_ == GZIP || ctx->mode_ == GUNZIP) {
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
323 ctx->windowBits_ += 16;
324 }
325
44eb279e »
2012-03-21 zlib: don't use C++ templates
326 if (ctx->mode_ == UNZIP) {
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
327 ctx->windowBits_ += 32;
328 }
329
44eb279e »
2012-03-21 zlib: don't use C++ templates
330 if (ctx->mode_ == DEFLATERAW || ctx->mode_ == INFLATERAW) {
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
331 ctx->windowBits_ *= -1;
332 }
333
44eb279e »
2012-03-21 zlib: don't use C++ templates
334 switch (ctx->mode_) {
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
335 case DEFLATE:
336 case GZIP:
337 case DEFLATERAW:
01d46f3a »
2012-03-31 Fix #3052 Handle errors properly in zlib
338 ctx->err_ = deflateInit2(&ctx->strm_,
339 ctx->level_,
340 Z_DEFLATED,
341 ctx->windowBits_,
342 ctx->memLevel_,
343 ctx->strategy_);
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
344 break;
345 case INFLATE:
346 case GUNZIP:
347 case INFLATERAW:
348 case UNZIP:
01d46f3a »
2012-03-31 Fix #3052 Handle errors properly in zlib
349 ctx->err_ = inflateInit2(&ctx->strm_, ctx->windowBits_);
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
350 break;
351 default:
352 assert(0 && "wtf?");
353 }
354
01d46f3a »
2012-03-31 Fix #3052 Handle errors properly in zlib
355 if (ctx->err_ != Z_OK) {
356 ZCtx::Error(ctx, "Init error");
357 }
358
e6091952 »
2011-12-02 [zlib] added dictionary support
359
360 ctx->dictionary_ = reinterpret_cast<Bytef *>(dictionary);
361 ctx->dictionary_len_ = dictionary_len;
362
71ae1753 »
2012-01-12 zlib: reset() method for deflate/inflate streams
363 ctx->write_in_progress_ = false;
364 ctx->init_done_ = true;
365 }
366
367 static void SetDictionary(ZCtx* ctx) {
368 if (ctx->dictionary_ == NULL) return;
e6091952 »
2011-12-02 [zlib] added dictionary support
369
01d46f3a »
2012-03-31 Fix #3052 Handle errors properly in zlib
370 ctx->err_ = Z_OK;
71ae1753 »
2012-01-12 zlib: reset() method for deflate/inflate streams
371
44eb279e »
2012-03-21 zlib: don't use C++ templates
372 switch (ctx->mode_) {
71ae1753 »
2012-01-12 zlib: reset() method for deflate/inflate streams
373 case DEFLATE:
374 case DEFLATERAW:
01d46f3a »
2012-03-31 Fix #3052 Handle errors properly in zlib
375 ctx->err_ = deflateSetDictionary(&ctx->strm_,
376 ctx->dictionary_,
377 ctx->dictionary_len_);
71ae1753 »
2012-01-12 zlib: reset() method for deflate/inflate streams
378 break;
379 default:
380 break;
e6091952 »
2011-12-02 [zlib] added dictionary support
381 }
382
01d46f3a »
2012-03-31 Fix #3052 Handle errors properly in zlib
383 if (ctx->err_ != Z_OK) {
384 ZCtx::Error(ctx, "Failed to set dictionary");
385 }
71ae1753 »
2012-01-12 zlib: reset() method for deflate/inflate streams
386 }
387
388 static void Reset(ZCtx* ctx) {
01d46f3a »
2012-03-31 Fix #3052 Handle errors properly in zlib
389 ctx->err_ = Z_OK;
71ae1753 »
2012-01-12 zlib: reset() method for deflate/inflate streams
390
44eb279e »
2012-03-21 zlib: don't use C++ templates
391 switch (ctx->mode_) {
71ae1753 »
2012-01-12 zlib: reset() method for deflate/inflate streams
392 case DEFLATE:
393 case DEFLATERAW:
01d46f3a »
2012-03-31 Fix #3052 Handle errors properly in zlib
394 ctx->err_ = deflateReset(&ctx->strm_);
71ae1753 »
2012-01-12 zlib: reset() method for deflate/inflate streams
395 break;
396 case INFLATE:
397 case INFLATERAW:
01d46f3a »
2012-03-31 Fix #3052 Handle errors properly in zlib
398 ctx->err_ = inflateReset(&ctx->strm_);
71ae1753 »
2012-01-12 zlib: reset() method for deflate/inflate streams
399 break;
400 default:
401 break;
402 }
403
01d46f3a »
2012-03-31 Fix #3052 Handle errors properly in zlib
404 if (ctx->err_ != Z_OK) {
405 ZCtx::Error(ctx, "Failed to reset stream");
406 }
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
407 }
408
409 private:
410
411 bool init_done_;
412
413 z_stream strm_;
414 int level_;
415 int windowBits_;
416 int memLevel_;
417 int strategy_;
418
01d46f3a »
2012-03-31 Fix #3052 Handle errors properly in zlib
419 int err_;
420
e6091952 »
2011-12-02 [zlib] added dictionary support
421 Bytef* dictionary_;
422 size_t dictionary_len_;
423
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
424 int flush_;
425
426 int chunk_size_;
8cca30f3 »
2012-01-10 zlib binding cleanup
427
428 bool write_in_progress_;
429
430 uv_work_t work_req_;
44eb279e »
2012-03-21 zlib: don't use C++ templates
431 node_zlib_mode mode_;
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
432 };
433
434
435 void InitZlib(Handle<Object> target) {
436 HandleScope scope;
437
44eb279e »
2012-03-21 zlib: don't use C++ templates
438 Local<FunctionTemplate> z = FunctionTemplate::New(ZCtx::New);
439
440 z->InstanceTemplate()->SetInternalFieldCount(1);
441
442 NODE_SET_PROTOTYPE_METHOD(z, "write", ZCtx::Write);
443 NODE_SET_PROTOTYPE_METHOD(z, "init", ZCtx::Init);
444 NODE_SET_PROTOTYPE_METHOD(z, "reset", ZCtx::Reset);
445
446 z->SetClassName(String::NewSymbol("Zlib"));
447 target->Set(String::NewSymbol("Zlib"), z->GetFunction());
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
448
449 callback_sym = NODE_PSYMBOL("callback");
01d46f3a »
2012-03-31 Fix #3052 Handle errors properly in zlib
450 onerror_sym = NODE_PSYMBOL("onerror");
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
451
452 NODE_DEFINE_CONSTANT(target, Z_NO_FLUSH);
453 NODE_DEFINE_CONSTANT(target, Z_PARTIAL_FLUSH);
454 NODE_DEFINE_CONSTANT(target, Z_SYNC_FLUSH);
455 NODE_DEFINE_CONSTANT(target, Z_FULL_FLUSH);
456 NODE_DEFINE_CONSTANT(target, Z_FINISH);
457 NODE_DEFINE_CONSTANT(target, Z_BLOCK);
01d46f3a »
2012-03-31 Fix #3052 Handle errors properly in zlib
458
459 // return/error codes
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
460 NODE_DEFINE_CONSTANT(target, Z_OK);
461 NODE_DEFINE_CONSTANT(target, Z_STREAM_END);
462 NODE_DEFINE_CONSTANT(target, Z_NEED_DICT);
463 NODE_DEFINE_CONSTANT(target, Z_ERRNO);
464 NODE_DEFINE_CONSTANT(target, Z_STREAM_ERROR);
465 NODE_DEFINE_CONSTANT(target, Z_DATA_ERROR);
466 NODE_DEFINE_CONSTANT(target, Z_MEM_ERROR);
467 NODE_DEFINE_CONSTANT(target, Z_BUF_ERROR);
468 NODE_DEFINE_CONSTANT(target, Z_VERSION_ERROR);
01d46f3a »
2012-03-31 Fix #3052 Handle errors properly in zlib
469
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
470 NODE_DEFINE_CONSTANT(target, Z_NO_COMPRESSION);
471 NODE_DEFINE_CONSTANT(target, Z_BEST_SPEED);
472 NODE_DEFINE_CONSTANT(target, Z_BEST_COMPRESSION);
473 NODE_DEFINE_CONSTANT(target, Z_DEFAULT_COMPRESSION);
474 NODE_DEFINE_CONSTANT(target, Z_FILTERED);
475 NODE_DEFINE_CONSTANT(target, Z_HUFFMAN_ONLY);
476 NODE_DEFINE_CONSTANT(target, Z_RLE);
477 NODE_DEFINE_CONSTANT(target, Z_FIXED);
478 NODE_DEFINE_CONSTANT(target, Z_DEFAULT_STRATEGY);
479 NODE_DEFINE_CONSTANT(target, ZLIB_VERNUM);
480
44eb279e »
2012-03-21 zlib: don't use C++ templates
481 NODE_DEFINE_CONSTANT(target, DEFLATE);
482 NODE_DEFINE_CONSTANT(target, INFLATE);
483 NODE_DEFINE_CONSTANT(target, GZIP);
484 NODE_DEFINE_CONSTANT(target, GUNZIP);
485 NODE_DEFINE_CONSTANT(target, DEFLATERAW);
486 NODE_DEFINE_CONSTANT(target, INFLATERAW);
487 NODE_DEFINE_CONSTANT(target, UNZIP);
488
5b8e1dab »
2011-09-06 Initial pass at zlib bindings
489 target->Set(String::NewSymbol("ZLIB_VERSION"), String::New(ZLIB_VERSION));
490 }
491
492 } // namespace node
493
cdcb1118 »
2011-11-09 Remove stray NODE_MODULE() semi-colons.
494 NODE_MODULE(node_zlib, node::InitZlib)
Something went wrong with that request. Please try again.