Initial commit

This commit is contained in:
anaarmas
2020-04-27 21:08:38 +02:00
commit ed9e55c0bf
13975 changed files with 2635882 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
build
.lock-wscript
Generated Vendored
+24
View File
@@ -0,0 +1,24 @@
Copyright (c) 2011, Konstantin Käfer <kkaefer@gmail.com>
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of node-zlib nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL Konstantin Käfer BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Generated Vendored
+15
View File
@@ -0,0 +1,15 @@
build:
node-waf build
clean:
node-waf clean
ifndef only
test: build
@expresso -I lib test/*.test.js
else
test: build
@expresso -I lib test/${only}.test.js
endif
.PHONY: build clean test
+54
View File
@@ -0,0 +1,54 @@
# NAME
node-zlib - Simple, synchronous deflate/inflate for node.js buffers.
# USAGE
Install with `npm install zlib`.
var Buffer = require('buffer').Buffer;
var zlib = require('zlib');
var input = new Buffer('lorem ipsum dolor sit amet');
var compressed = zlib.deflate(input);
var output = zlib.inflate(compressed);
Note that `node-zlib` is only intended for small (< 128 KB) data that you already have buffered. It is not meant for input/output streams.
# BUILDING
Make sure you have `zlib` installed. Mac OS X ships with it by default.
To obtain and build the bindings:
git clone git://github.com/kkaefer/node-zlib.git
cd node-zlib
./configure
make
You can also use [`npm`](https://github.com/isaacs/npm) to download and install them:
npm install zlib
# TESTS
[expresso](https://github.com/visionmedia/expresso) is required to run unit tests.
npm install expresso
make test
# CONTRIBUTORS
* [Konstantin Käfer](https://github.com/kkaefer)
# LICENSE
`node-zlib` is [BSD licensed](https://github.com/kkaefer/node-zlib/raw/master/LICENSE).
Generated Vendored Executable
+2
View File
@@ -0,0 +1,2 @@
#!/bin/sh
node-waf configure
Generated Vendored
+1
View File
@@ -0,0 +1 @@
module.exports = require('./lib/zlib');
+1
View File
@@ -0,0 +1 @@
module.exports = require('./zlib_bindings');
+52
View File
@@ -0,0 +1,52 @@
{
"_from": "zlib",
"_id": "zlib@1.0.5",
"_inBundle": false,
"_integrity": "sha1-bnyXL8NxxkWmr7A6sUdp3vEU/MA=",
"_location": "/zlib",
"_phantomChildren": {},
"_requested": {
"type": "tag",
"registry": true,
"raw": "zlib",
"name": "zlib",
"escapedName": "zlib",
"rawSpec": "",
"saveSpec": null,
"fetchSpec": "latest"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npmjs.org/zlib/-/zlib-1.0.5.tgz",
"_shasum": "6e7c972fc371c645a6afb03ab14769def114fcc0",
"_spec": "zlib",
"_where": "/Users/ana/Semmle/Anthophila/codeql-action",
"author": {
"name": "Konstantin Käfer",
"email": "kkaefer@gmail.com"
},
"bugs": {
"url": "https://github.com/kkaefer/node-zlib/issues"
},
"bundleDependencies": false,
"deprecated": false,
"description": "Simple, synchronous deflate/inflate for buffers",
"engines": {
"node": ">=0.2.0"
},
"homepage": "https://github.com/kkaefer/node-zlib",
"licenses": [
{
"type": "BSD"
}
],
"main": "./lib/zlib",
"name": "zlib",
"repository": {
"type": "git",
"url": "git://github.com/kkaefer/node-zlib.git"
},
"version": "1.0.5"
}
+95
View File
@@ -0,0 +1,95 @@
#include <v8.h>
#include <node.h>
#include <node_buffer.h>
#include <node_version.h>
#include <zlib.h>
#include <cstring>
#include <cstdlib>
using namespace v8;
using namespace node;
// node v0.2.x compatibility
#if NODE_VERSION_AT_LEAST(0,3,0)
#define Buffer_Data Buffer::Data
#define Buffer_Length Buffer::Length
#define Buffer_New Buffer::New
#else
inline char* Buffer_Data(Handle<Object> obj) {
return (ObjectWrap::Unwrap<Buffer>(obj))->data();
}
inline size_t Buffer_Length(Handle<Object> obj) {
return (ObjectWrap::Unwrap<Buffer>(obj))->length();
}
inline Buffer* Buffer_New(char* data, size_t length) {
Buffer* buffer = Buffer::New(length);
memcpy(buffer->data(), data, length);
return buffer;
}
#endif
z_stream deflate_s;
z_stream inflate_s;
inline Handle<Value> ZLib_error(const char* msg = NULL) {
return ThrowException(Exception::Error(
String::New(msg ? msg : "Unknown Error")));
}
#define ZLib_Xflate(x, factor) \
Handle<Value> ZLib_##x##flate(const Arguments& args) { \
HandleScope scope; \
\
if (args.Length() < 1 || !Buffer::HasInstance(args[0])) { \
return ZLib_error("Expected Buffer as first argument"); \
} \
\
if ((x##flateReset(&x##flate_s)) != Z_OK) { \
assert((false, "ZLib stream is beyond repair")); \
} \
\
Local<Object> input = args[0]->ToObject(); \
x##flate_s.next_in = (Bytef*)Buffer_Data(input); \
int length = x##flate_s.avail_in = Buffer_Length(input); \
\
int ret; \
char* result = NULL; \
\
int compressed = 0; \
do { \
result = (char*)realloc(result, compressed + factor * length); \
if (!result) return ZLib_error("Could not allocate memory"); \
\
x##flate_s.avail_out = factor * length; \
x##flate_s.next_out = (Bytef*)result + compressed; \
\
ret = x##flate(&x##flate_s, Z_FINISH); \
if (ret != Z_STREAM_END && ret != Z_OK && ret != Z_BUF_ERROR) { \
free(result); \
return ZLib_error(x##flate_s.msg); \
} \
\
compressed += (factor * length - x##flate_s.avail_out); \
} while (x##flate_s.avail_out == 0); \
\
Buffer* output = Buffer_New(result, compressed); \
free(result); \
return scope.Close(Local<Value>::New(output->handle_)); \
}
ZLib_Xflate(de, 1);
ZLib_Xflate(in, 2);
extern "C" void init (Handle<Object> target) {
deflate_s.zalloc = inflate_s.zalloc = Z_NULL;
deflate_s.zfree = inflate_s.zfree = Z_NULL;
deflate_s.opaque = inflate_s.opaque = Z_NULL;
deflateInit(&deflate_s, Z_DEFAULT_COMPRESSION);
inflateInit(&inflate_s);
NODE_SET_METHOD(target, "deflate", ZLib_deflate);
NODE_SET_METHOD(target, "inflate", ZLib_inflate);
}
+23
View File
File diff suppressed because one or more lines are too long
+33
View File
@@ -0,0 +1,33 @@
var assert = require('assert');
var Buffer = require('buffer').Buffer;
var zlib = require('../lib/zlib');
exports['test header inflate fail'] = function(beforeExit) {
var compressed = new Buffer('\x78\x80\x9c\xab\x56\x4a\x93\xaf\x46\x00\x1b\xa9\x02\x77\x92\x0f', 'binary');
assert.throws(function() { var output = zlib.inflate(compressed); },
"incorrect header check");
var compressed = new Buffer('\x78\x9c\xab\x56\x4a\x2f\xca\x4c\x51\xb2\x8a\x56\x52\xa0\x10\x28\xe9\x8c\x1a\x31\x6a\xc4\xa8\x11\xa3\x46\x8c\x1a\x31\x6a\xc4\xa8\x11\xa3\x46\x8c\x1a\x31\x6a\x04\x12\x50\x04\x02\x2a\x18\x01\x01\x64\x1b\x81\x64\x06\xdc\x10\xd2\x8c\x50\x44\x36\x02\x66\x06\x05\xae\x80\x99\x41\x72\x8c\x60\x9a\x41\x46\xa4\x0e\x0e\x23\x80\x81\xaa\x40\xa9\x11\x0a\x28\x46\x28\x52\xe6\x0a\x45\x0a\x8c\x40\x0e\x10\xf2\xb3\x19\x15\x8c\x80\x1b\x42\x69\x66\x57\x54\x54\xa6\xbc\xbc\xa0\x82\x11\x43\xb3\xe0\x1b\x42\x46\xa8\x50\xc1\x15\x2a\xa4\x1a\x42\xb9\x47\x54\x95\x62\x75\x94\xb2\x53\x2b\x8b\x41\x03\x19\x40\xe3\x7c\x23\x80\x84\x7b\x08\x90\xf0\x0e\x02\x12\xae\xce\x4a\xb1\xb5\x00\x83\x32\x27\xf3', 'binary');
var output = zlib.inflate(compressed);
assert.equal(output.toString(), '{"grid":[" "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," !!!! "," !!!!!!!!!! "," !!!!!!!!!!! "," ! !!!!!!!!!!!! "," !!!!!!!!!!!!! "," !!!!!!!!!!!!! "," !!!!!!!!!!! "," !!!!!!!!!!! "," ! !!!!!!! "," !!!!!!! !"," ! !!!!!!!! !"," ! !!!!!!!!!!!"," !!!!!!!!!"," !!!!!!!"," !!#"," #"," "," "," "," "," "," "," $ "," $$ "," %"],"keys":["","MX","GT","KR","EC"]}');
};
exports['test truncated inflate fail'] = function(beforeExit) {
var compressed = new Buffer('\x78\x9c\xab\x56\x4a\x2f\xca\x4c\x51\xb2\x8a\x56\x52\xa0\x10\x28\xe9\x8c\x1a\x31\x6a\xc4\xa8\x11\xa3\x46\x8c\x1a\x31\x6a\xc4\xa8\x11\xa3\x46\x8c\x1a\x31\x6a\x04\x12\x50\x04\x02\x2a\x18\x01\x01\x64\x1b\x81\x64\x06\xdc\x10\xd2\x8c\x50\x44\x36\x02\x66\x06\x05\xae\x80\x99\x41\x72\x8c\x60\x9a\x41\x46\xa4\x0e\x0e\x23\x80\x81\xaa\x40\xa9\x11\x0a\x28\x46\x28\x52\xe6\x0a\x45\x0a\x8c\x40\x0e\x10\xf2\xb3\x19\x15\x8c\x80\x1b\x42\x69\x66\x57\x54\x54\xa6', 'binary');
var output = zlib.inflate(compressed);
assert.equal(output.toString(), '{"grid":[" "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," !!!! "," !!!!!!!!!! "," !!!!!!!!!!! "," ! !!!!!!!!!!!! "," !!!!!!!!!!!!! "," !!!!!!!!!!!!! "," !!!!!!!!!!! "," !!!!!!!!!!! "," ! !!!!!!! "," !!!!!!! !"," ! !!!!!!!! !"," ! !!!!!!!!!!!"," !!!!!!!!!"," !!!!!!!"," !!#');
var compressed = new Buffer('\x78\x9c\xab\x56\x4a\x2f\xca\x4c\x51\xb2\x8a\x56\x52\xa0\x10\x28\xe9\x8c\x1a\x31\x6a\xc4\xa8\x11\xa3\x46\x8c\x1a\x31\x6a\xc4\xa8\x11\xa3\x46\x8c\x1a\x31\x6a\x04\x12\x50\x04\x02\x2a\x18\x01\x01\x64\x1b\x81\x64\x06\xdc\x10\xd2\x8c\x50\x44\x36\x02\x66\x06\x05\xae\x80\x99\x41\x72\x8c\x60\x9a\x41\x46\xa4\x0e\x0e\x23\x80\x81\xaa\x40\xa9\x11\x0a\x28\x46\x28\x52\xe6\x0a\x45\x0a\x8c\x40\x0e\x10\xf2\xb3\x19\x15\x8c\x80\x1b\x42\x69\x66\x57\x54\x54\xa6\xbc\xbc\xa0\x82\x11\x43\xb3\xe0\x1b\x42\x46\xa8\x50\xc1\x15\x2a\xa4\x1a\x42\xb9\x47\x54\x95\x62\x75\x94\xb2\x53\x2b\x8b\x41\x03\x19\x40\xe3\x7c\x23\x80\x84\x7b\x08\x90\xf0\x0e\x02\x12\xae\xce\x4a\xb1\xb5\x00\x83\x32\x27\xf3', 'binary');
var output = zlib.inflate(compressed);
assert.equal(output.toString(), '{"grid":[" "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," !!!! "," !!!!!!!!!! "," !!!!!!!!!!! "," ! !!!!!!!!!!!! "," !!!!!!!!!!!!! "," !!!!!!!!!!!!! "," !!!!!!!!!!! "," !!!!!!!!!!! "," ! !!!!!!! "," !!!!!!! !"," ! !!!!!!!! !"," ! !!!!!!!!!!!"," !!!!!!!!!"," !!!!!!!"," !!#"," #"," "," "," "," "," "," "," $ "," $$ "," %"],"keys":["","MX","GT","KR","EC"]}');
};
exports['test bogus inflate fail'] = function(beforeExit) {
var compressed = new Buffer('bahbahfoobar', 'binary');
assert.throws(function() { var output = zlib.inflate(compressed); },
"incorrect header check");
var compressed = new Buffer('\x78\x9c\xab\x56\x4a\x2f\xca\x4c\x51\xb2\x8a\x56\x52\xa0\x10\x28\xe9\x8c\x1a\x31\x6a\xc4\xa8\x11\xa3\x46\x8c\x1a\x31\x6a\xc4\xa8\x11\xa3\x46\x8c\x1a\x31\x6a\x04\x12\x50\x04\x02\x2a\x18\x01\x01\x64\x1b\x81\x64\x06\xdc\x10\xd2\x8c\x50\x44\x36\x02\x66\x06\x05\xae\x80\x99\x41\x72\x8c\x60\x9a\x41\x46\xa4\x0e\x0e\x23\x80\x81\xaa\x40\xa9\x11\x0a\x28\x46\x28\x52\xe6\x0a\x45\x0a\x8c\x40\x0e\x10\xf2\xb3\x19\x15\x8c\x80\x1b\x42\x69\x66\x57\x54\x54\xa6\xbc\xbc\xa0\x82\x11\x43\xb3\xe0\x1b\x42\x46\xa8\x50\xc1\x15\x2a\xa4\x1a\x42\xb9\x47\x54\x95\x62\x75\x94\xb2\x53\x2b\x8b\x41\x03\x19\x40\xe3\x7c\x23\x80\x84\x7b\x08\x90\xf0\x0e\x02\x12\xae\xce\x4a\xb1\xb5\x00\x83\x32\x27\xf3', 'binary');
var output = zlib.inflate(compressed);
assert.equal(output.toString(), '{"grid":[" "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," !!!! "," !!!!!!!!!! "," !!!!!!!!!!! "," ! !!!!!!!!!!!! "," !!!!!!!!!!!!! "," !!!!!!!!!!!!! "," !!!!!!!!!!! "," !!!!!!!!!!! "," ! !!!!!!! "," !!!!!!! !"," ! !!!!!!!! !"," ! !!!!!!!!!!!"," !!!!!!!!!"," !!!!!!!"," !!#"," #"," "," "," "," "," "," "," $ "," $$ "," %"],"keys":["","MX","GT","KR","EC"]}');
};
Generated Vendored
+38
View File
@@ -0,0 +1,38 @@
import os
import Options
from os.path import exists
from shutil import copy2 as copy
TARGET = 'zlib_bindings'
TARGET_FILE = '%s.node' % TARGET
built = 'build/default/%s' % TARGET_FILE
dest = 'lib/%s' % TARGET_FILE
def set_options(opt):
opt.tool_options("compiler_cxx")
def configure(conf):
conf.check_tool("compiler_cxx")
conf.check_tool("node_addon")
if not conf.check(lib="z", libpath=['/usr/local/lib'], uselib_store="ZLIB"):
conf.fatal('Missing zlib');
linkflags = []
if os.environ.has_key('LINKFLAGS'):
linkflags.extend(os.environ['LINKFLAGS'].split(' '))
conf.env.append_value("LINKFLAGS", linkflags)
def build(bld):
obj = bld.new_task_gen("cxx", "shlib", "node_addon")
obj.cxxflags = ["-g", "-D_FILE_OFFSET_BITS=64", "-D_LARGEFILE_SOURCE", "-Wall"]
obj.target = TARGET
obj.source = "src/node-zlib.cc"
obj.uselib = "ZLIB"
def shutdown():
if Options.commands['clean']:
if exists(TARGET_FILE):
unlink(TARGET_FILE)
else:
if exists(built):
copy(built, dest)