Upload Kmake

This commit is contained in:
Gorochu
2026-05-26 23:36:42 -07:00
parent ba051b2f74
commit 555ec72358
41615 changed files with 13344630 additions and 1 deletions

View File

@ -0,0 +1,58 @@
#include <node.h>
#include <node_buffer.h>
#include <zlib.h>
#include <assert.h>
namespace {
inline void CompressBytes(const v8::FunctionCallbackInfo<v8::Value>& info) {
assert(info[0]->IsArrayBufferView());
auto view = info[0].As<v8::ArrayBufferView>();
auto byte_offset = view->ByteOffset();
auto byte_length = view->ByteLength();
assert(view->HasBuffer());
auto buffer = view->Buffer();
auto contents = buffer->GetBackingStore();
auto data = static_cast<unsigned char*>(contents->Data()) + byte_offset;
Bytef buf[1024];
z_stream stream;
stream.zalloc = nullptr;
stream.zfree = nullptr;
int err = deflateInit2(&stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED,
-15, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY);
assert(err == Z_OK);
stream.avail_in = byte_length;
stream.next_in = data;
stream.avail_out = sizeof(buf);
stream.next_out = buf;
err = deflate(&stream, Z_FINISH);
assert(err == Z_STREAM_END);
auto result = node::Buffer::Copy(info.GetIsolate(),
reinterpret_cast<const char*>(buf),
sizeof(buf) - stream.avail_out);
deflateEnd(&stream);
info.GetReturnValue().Set(result.ToLocalChecked());
}
inline void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> module,
v8::Local<v8::Context> context) {
auto isolate = context->GetIsolate();
auto key = v8::String::NewFromUtf8(
isolate, "compressBytes").ToLocalChecked();
auto value = v8::FunctionTemplate::New(isolate, CompressBytes)
->GetFunction(context)
.ToLocalChecked();
assert(exports->Set(context, key, value).IsJust());
}
} // anonymous namespace
NODE_MODULE_CONTEXT_AWARE(NODE_GYP_MODULE_NAME, Initialize)

View File

@ -0,0 +1,25 @@
{
'targets': [
{
'target_name': 'binding',
'conditions': [
['OS in "aix os400"', {
'variables': {
# Used to differentiate `AIX` and `OS400`(IBM i).
'aix_variant_name': '<!(uname -s)',
},
'conditions': [
[ '"<(aix_variant_name)"!="OS400"', { # Not `OS400`(IBM i)
'sources': ['binding.cc'],
'include_dirs': ['../../../deps/zlib'],
}],
],
}, {
'sources': ['binding.cc'],
'include_dirs': ['../../../deps/zlib'],
}],
],
'includes': ['../common.gypi'],
},
]
}

View File

@ -0,0 +1,13 @@
// Flags: --force-context-aware
'use strict';
const common = require('../../common');
const assert = require('assert');
const zlib = require('zlib');
const binding = require(`./build/${common.buildType}/binding`);
const input = Buffer.from('Hello, World!');
const output = zlib.inflateRawSync(binding.compressBytes(input));
assert.deepStrictEqual(input, output);