#include <node.h>
#include <node_buffer.h>
- #include <req_wrap.h>
-
- #include <node_vars.h>
+#include <node_vars.h>
+// We do the following to minimize the detal between v0.6 branch. We want to
+// use the variables as they were being used before.
+#define callback_sym NODE_VAR(callback_sym)
namespace node {
using namespace v8;
- // write() returns one of these, and then calls the cb() when it's done.
- typedef ReqWrap<uv_work_t> WorkReqWrap;
-static Persistent<String> callback_sym;
-
enum node_zlib_mode {
DEFLATE = 1,
INFLATE,
// set this so that later on, I can easily tell how much was written.
ctx->chunk_size_ = out_len;
- // build up the work request
- uv_work_t* work_req = new uv_work_t();
- work_req->data = req_wrap;
-
- uv_queue_work(uv_default_loop(),
+ uv_queue_work(Loop(),
work_req,
ZCtx<mode>::Process,
ZCtx<mode>::After);
case INFLATE:
case GUNZIP:
case INFLATERAW:
- err = inflate(&(ctx->strm_), ctx->flush_);
+ err = inflate(&ctx->strm_, ctx->flush_);
+
+ // If data was encoded with dictionary
+ if (err == Z_NEED_DICT) {
+ assert(ctx->dictionary_ != NULL && "Stream has no dictionary");
+
+ // Load it
+ err = inflateSetDictionary(
+ &(ctx->strm_),
+ ctx->dictionary_,
+ ctx->dictionary_len_
+ );
+ assert(err == Z_OK && "Failed to set dictionary");
+
+ // And try to decode again
+ err = inflate(&(ctx->strm_), ctx->flush_);
+ }
break;
default:
assert(0 && "wtf?");
}
// just pull the ints out of the args and call the other Init
- static Handle<Value>
- Init(const Arguments& args) {
+ static Handle<Value> Init(const Arguments& args) {
HandleScope scope;
- assert(args.Length() == 4 &&
- "init(windowBits, level, memLevel, strategy)");
+ assert((args.Length() == 4 || args.Length() == 5) &&
+ "init(windowBits, level, memLevel, strategy, [dictionary])");
ZCtx<mode> *ctx = ObjectWrap::Unwrap< ZCtx<mode> >(args.This());
return Undefined();
}
- static void
- Init(ZCtx *ctx,
- int level,
- int windowBits,
- int memLevel,
- int strategy,
- char* dictionary,
- size_t dictionary_len) {
+ static void Init(ZCtx *ctx, int level, int windowBits, int memLevel,
- int strategy) {
++ int strategy, char* dictionary, size_t dictionary_len) {
ctx->level_ = level;
ctx->windowBits_ = windowBits;
ctx->memLevel_ = memLevel;
assert(0 && "wtf?");
}
+ assert(err == Z_OK);
+
+ ctx->dictionary_ = reinterpret_cast<Bytef *>(dictionary);
+ ctx->dictionary_len_ = dictionary_len;
+
+ if (dictionary != NULL) {
+ switch (mode) {
+ case DEFLATE:
+ case DEFLATERAW:
+ err = deflateSetDictionary(
+ &(ctx->strm_),
+ ctx->dictionary_,
+ dictionary_len
+ );
+ break;
+ default:
+ break;
+ }
+
+ assert(err == Z_OK && "Failed to set dictionary");
+ }
+
+ ctx->write_in_progress_ = false;
ctx->init_done_ = true;
- assert(err == Z_OK);
}
private:
Get(String::NewSymbol("windowsVerbatimArguments"))->IsTrue();
#endif
- int r = uv_spawn(uv_default_loop(), &wrap->process_, options);
+ int r = uv_spawn(Loop(), &wrap->process_, options);
- wrap->SetHandle((uv_handle_t*)&wrap->process_);
- assert(wrap->process_.data == wrap);
-
- wrap->object_->Set(String::New("pid"), Integer::New(wrap->process_.pid));
+ if (r) {
- SetErrno(uv_last_error(uv_default_loop()));
++ SetErrno(uv_last_error(Loop()));
+ }
+ else {
+ wrap->SetHandle((uv_handle_t*)&wrap->process_);
+ assert(wrap->process_.data == wrap);
+ wrap->object_->Set(String::New("pid"), Integer::New(wrap->process_.pid));
+ }
if (options.args) {
for (int i = 0; options.args[i]; i++) free(options.args[i]);
#include <tcp_wrap.h>
#include <req_wrap.h>
+#include <node_vars.h>
+
+// We do the following to minimize the detal between v0.6 branch. We want to
+// use the variables as they were being used before.
+#define slab_used NODE_VAR(slab_used)
+#define slab_sym NODE_VAR(slab_sym)
+#define handle_that_last_alloced NODE_VAR(handle_that_last_alloced)
+#define buffer_sym NODE_VAR(buffer_sym)
++#define buffer_constructor_template NODE_VAR(buffer_constructor_template)
+#define write_queue_size_sym NODE_VAR(write_queue_size_sym)
+#define stream_wrap_initialized NODE_VAR(stream_wrap_initialized)
+
namespace node {
}
- inline char* StreamWrap::NewSlab(Handle<Object> global,
- Handle<Object> wrap_obj) {
- Buffer* b = Buffer::New(SLAB_SIZE);
- global->SetHiddenValue(slab_sym, b->handle_);
+ char* StreamWrap::NewSlab(Handle<Object> global,
+ Handle<Object> wrap_obj) {
+ HandleScope scope;
+ Local<Value> arg = Integer::NewFromUnsigned(SLAB_SIZE);
- Local<Object> b = Buffer::constructor_template->GetFunction()->
++ Local<Object> b = buffer_constructor_template->GetFunction()->
+ NewInstance(1, &arg);
+ if (b.IsEmpty()) return NULL;
+ global->SetHiddenValue(slab_sym, b);
assert(Buffer::Length(b) == SLAB_SIZE);
slab_used = 0;
- wrap_obj->SetHiddenValue(slab_sym, b->handle_);
+ wrap_obj->SetHiddenValue(slab_sym, b);
return Buffer::Data(b);
}