summaryrefslogtreecommitdiff
path: root/src/node_zlib.cc
diff options
context:
space:
mode:
authorLuis Reis <luis.m.reis@gmail.com>2014-09-09 17:30:15 +0100
committerFedor Indutny <fedor@indutny.com>2014-11-09 05:09:10 +0300
commit1183ba47dfc2bc8b39f0c10d8dc9e9299a4470bf (patch)
tree100d971bf322c6da6fc4a1ed89dcb233dee25dd1 /src/node_zlib.cc
parent1bb0aeb8f2214702da18a172a0f26d6118e7cc82 (diff)
downloadandroid-node-v8-1183ba47dfc2bc8b39f0c10d8dc9e9299a4470bf.tar.gz
android-node-v8-1183ba47dfc2bc8b39f0c10d8dc9e9299a4470bf.tar.bz2
android-node-v8-1183ba47dfc2bc8b39f0c10d8dc9e9299a4470bf.zip
zlib: support concatenated gzip files
Reviewed-By: Fedor Indutny <fedor@indutny.com> PR-URL: https://github.com/joyent/node/pull/6442
Diffstat (limited to 'src/node_zlib.cc')
-rw-r--r--src/node_zlib.cc31
1 files changed, 24 insertions, 7 deletions
diff --git a/src/node_zlib.cc b/src/node_zlib.cc
index cfa5b8cd6e..65cf71e79c 100644
--- a/src/node_zlib.cc
+++ b/src/node_zlib.cc
@@ -63,6 +63,11 @@ enum node_zlib_mode {
UNZIP
};
+enum node_zlib_error {
+ NO_ERROR,
+ FAILED,
+ WRITE_PENDING
+};
void InitZlib(v8::Handle<v8::Object> target);
@@ -203,7 +208,7 @@ class ZCtx : public AsyncWrap {
if (!async) {
// sync version
Process(work_req);
- if (CheckError(ctx))
+ if (CheckError(ctx) == NO_ERROR)
AfterSync(ctx, args);
return;
}
@@ -287,7 +292,7 @@ class ZCtx : public AsyncWrap {
}
- static bool CheckError(ZCtx* ctx) {
+ static node_zlib_error CheckError(ZCtx* ctx) {
// Acceptable error states depend on the type of zlib stream.
switch (ctx->err_) {
case Z_OK:
@@ -300,14 +305,18 @@ class ZCtx : public AsyncWrap {
ZCtx::Error(ctx, "Missing dictionary");
else
ZCtx::Error(ctx, "Bad dictionary");
- return false;
+ return FAILED;
default:
// something else.
- ZCtx::Error(ctx, "Zlib error");
- return false;
+ if (ctx->strm_.total_out == 0) {
+ ZCtx::Error(ctx, "Zlib error");
+ return FAILED;
+ } else {
+ return WRITE_PENDING;
+ }
}
- return true;
+ return NO_ERROR;
}
@@ -321,7 +330,8 @@ class ZCtx : public AsyncWrap {
HandleScope handle_scope(env->isolate());
Context::Scope context_scope(env->context());
- if (!CheckError(ctx))
+ node_zlib_error error = CheckError(ctx);
+ if (error == FAILED)
return;
Local<Integer> avail_out = Integer::New(env->isolate(),
@@ -335,6 +345,11 @@ class ZCtx : public AsyncWrap {
Local<Value> args[2] = { avail_in, avail_out };
ctx->MakeCallback(env->callback_string(), ARRAY_SIZE(args), args);
+ if (error == WRITE_PENDING) {
+ ZCtx::Error(ctx, "Zlib error");
+ return;
+ }
+
ctx->Unref();
if (ctx->pending_close_)
ctx->Close();
@@ -539,10 +554,12 @@ class ZCtx : public AsyncWrap {
switch (ctx->mode_) {
case DEFLATE:
case DEFLATERAW:
+ case GZIP:
ctx->err_ = deflateReset(&ctx->strm_);
break;
case INFLATE:
case INFLATERAW:
+ case GUNZIP:
ctx->err_ = inflateReset(&ctx->strm_);
break;
default: