mirror of
https://github.com/oven-sh/bun
synced 2026-02-04 07:58:54 +00:00
Compare commits
11 Commits
dylan/pyth
...
jarred/bro
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9c4ab91459 | ||
|
|
9a2bce2102 | ||
|
|
df0db54c58 | ||
|
|
0fd493fd78 | ||
|
|
ba43fdf317 | ||
|
|
1becd014fa | ||
|
|
6924134cd5 | ||
|
|
3a2e66ab62 | ||
|
|
802f9ccb58 | ||
|
|
c676a64ce4 | ||
|
|
0119b623d4 |
9
.gitmodules
vendored
9
.gitmodules
vendored
@@ -74,4 +74,11 @@ fetchRecurseSubmodules = false
|
||||
url = https://github.com/aklomp/base64.git
|
||||
ignore = dirty
|
||||
depth = 1
|
||||
shallow = true
|
||||
shallow = true
|
||||
[submodule "src/deps/brotli"]
|
||||
path = src/deps/brotli
|
||||
url = https://github.com/google/brotli.git
|
||||
ignore = dirty
|
||||
depth = 1
|
||||
shallow = true
|
||||
fetchRecurseSubmodules = false
|
||||
23
Dockerfile
23
Dockerfile
@@ -316,6 +316,28 @@ WORKDIR $BUN_DIR
|
||||
RUN cd $BUN_DIR && \
|
||||
make base64 && rm -rf src/deps/base64 Makefile
|
||||
|
||||
FROM bun-base as brotli
|
||||
|
||||
ARG DEBIAN_FRONTEND
|
||||
ARG GITHUB_WORKSPACE
|
||||
ARG ZIG_PATH
|
||||
# Directory extracts to "bun-webkit"
|
||||
ARG WEBKIT_DIR
|
||||
ARG BUN_RELEASE_DIR
|
||||
ARG BUN_DEPS_OUT_DIR
|
||||
ARG BUN_DIR
|
||||
ARG CPU_TARGET
|
||||
ENV CPU_TARGET=${CPU_TARGET}
|
||||
|
||||
COPY Makefile ${BUN_DIR}/Makefile
|
||||
COPY src/deps/brotli ${BUN_DIR}/src/deps/brotli
|
||||
|
||||
WORKDIR $BUN_DIR
|
||||
|
||||
RUN cd $BUN_DIR && \
|
||||
make brotli && rm -rf src/deps/brotli Makefile
|
||||
|
||||
|
||||
FROM bun-base as picohttp
|
||||
|
||||
ARG DEBIAN_FRONTEND
|
||||
@@ -578,6 +600,7 @@ ENV LIB_ICU_PATH=${WEBKIT_DIR}/lib
|
||||
|
||||
COPY --from=zlib ${BUN_DEPS_OUT_DIR}/*.a ${BUN_DEPS_OUT_DIR}/
|
||||
COPY --from=base64 ${BUN_DEPS_OUT_DIR}/*.a ${BUN_DEPS_OUT_DIR}/
|
||||
COPY --from=brotli ${BUN_DEPS_OUT_DIR}/*.a ${BUN_DEPS_OUT_DIR}/
|
||||
COPY --from=libarchive ${BUN_DEPS_OUT_DIR}/*.a ${BUN_DEPS_OUT_DIR}/
|
||||
COPY --from=boringssl ${BUN_DEPS_OUT_DIR}/*.a ${BUN_DEPS_OUT_DIR}/
|
||||
COPY --from=lolhtml ${BUN_DEPS_OUT_DIR}/*.a ${BUN_DEPS_OUT_DIR}/
|
||||
|
||||
32
Makefile
32
Makefile
@@ -462,6 +462,9 @@ ARCHIVE_FILES_WITHOUT_LIBCRYPTO = $(MINIMUM_ARCHIVE_FILES) \
|
||||
-lusockets \
|
||||
-lcares \
|
||||
-lzstd \
|
||||
-lbrotlicommon \
|
||||
-lbrotlienc \
|
||||
-lbrotlidec \
|
||||
$(BUN_DEPS_OUT_DIR)/libuwsockets.o
|
||||
|
||||
ARCHIVE_FILES = $(ARCHIVE_FILES_WITHOUT_LIBCRYPTO)
|
||||
@@ -863,6 +866,18 @@ fetch: $(IO_FILES)
|
||||
$(CXX) $(PACKAGE_DIR)/fetch.o -g $(OPTIMIZATION_LEVEL) -o ./misctools/fetch $(IO_FILES) $(DEFAULT_LINKER_FLAGS) -lc $(MINIMUM_ARCHIVE_FILES)
|
||||
rm -rf $(PACKAGE_DIR)/fetch.o
|
||||
|
||||
.PHONY: stream-tester
|
||||
stream-tester:
|
||||
$(ZIG) build -Doptimize=ReleaseFast stream-tester-obj
|
||||
$(CXX) $(PACKAGE_DIR)/stream-tester.o -g $(OPTIMIZATION_LEVEL) -o ./misctools/stream-tester $(DEFAULT_LINKER_FLAGS) -lc $(ARCHIVE_FILES) $(ICU_FLAGS)
|
||||
rm -rf $(PACKAGE_DIR)/stream-tester.o
|
||||
|
||||
.PHONY: stream-tester-debug
|
||||
stream-tester-debug:
|
||||
$(ZIG) build stream-tester-obj -Doptimize=Debug
|
||||
$(CXX) $(DEBUG_PACKAGE_DIR)/stream-tester.o -g3 -o ./misctools/stream-tester $(DEFAULT_LINKER_FLAGS) -lc $(ARCHIVE_FILES) $(ICU_FLAGS)
|
||||
|
||||
|
||||
.PHONY: sha
|
||||
sha:
|
||||
$(ZIG) build -Doptimize=ReleaseFast sha-bench-obj
|
||||
@@ -1366,6 +1381,20 @@ mimalloc:
|
||||
&& ninja;
|
||||
cp $(BUN_DEPS_DIR)/mimalloc/$(MIMALLOC_INPUT_PATH) $(BUN_DEPS_OUT_DIR)/$(MIMALLOC_FILE)
|
||||
|
||||
.PHONY: brotli
|
||||
brotli:
|
||||
rm -rf $(BUN_DEPS_DIR)/brotli/CMakeCache* $(BUN_DEPS_DIR)/brotli/CMakeFiles && (cd src/deps/brotli && make clean || echo "")
|
||||
cd $(BUN_DEPS_DIR)/brotli; \
|
||||
cmake $(CMAKE_FLAGS) \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DBROTLI_DISABLE_TESTS=ON \
|
||||
-DBROTLI_BUNDLED_MODE=ON \
|
||||
-DBUILD_SHARED_LIBS=OFF \
|
||||
-DCMAKE_C_FLAGS="$(CFLAGS)" \
|
||||
-DCMAKE_CXX_FLAGS="$(CFLAGS)" \
|
||||
-GNinja \
|
||||
. \
|
||||
&& ninja && cp libbrotli*.a $(BUN_DEPS_OUT_DIR);
|
||||
|
||||
mimalloc-wasm:
|
||||
cd $(BUN_DEPS_DIR)/mimalloc; emcmake cmake -DMI_BUILD_SHARED=OFF -DMI_BUILD_STATIC=ON -DMI_BUILD_TESTS=OFF -DMI_BUILD_OBJECT=ON ${MIMALLOC_OVERRIDE_FLAG} -DMI_USE_CXX=ON .; emmake make;
|
||||
@@ -1879,8 +1908,7 @@ cold-jsc-start:
|
||||
misctools/cold-jsc-start.cpp -o cold-jsc-start
|
||||
|
||||
.PHONY: vendor-without-npm
|
||||
vendor-without-npm: node-fallbacks runtime_js fallback_decoder bun_error mimalloc picohttp zlib boringssl libarchive lolhtml sqlite usockets uws tinycc c-ares zstd base64
|
||||
|
||||
vendor-without-npm: node-fallbacks runtime_js fallback_decoder bun_error mimalloc picohttp zlib boringssl libarchive lolhtml sqlite usockets uws tinycc c-ares zstd base64 brotli
|
||||
|
||||
.PHONY: vendor-without-check
|
||||
vendor-without-check: npm-install vendor-without-npm
|
||||
|
||||
13
build.zig
13
build.zig
@@ -381,6 +381,19 @@ pub fn build(b: *Build) !void {
|
||||
headers_obj.addOptions("build_options", default_build_options.step(b));
|
||||
}
|
||||
|
||||
{
|
||||
const headers_step = b.step("stream-tester-obj", "Build stream-tester (object files)");
|
||||
var headers_obj = b.addObject(.{
|
||||
.name = "stream-tester",
|
||||
.root_source_file = FileSource.relative("src/stream_tester.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
defer headers_step.dependOn(&headers_obj.step);
|
||||
try configureObjectStep(b, headers_obj, @TypeOf(target), target, obj.main_pkg_path.?);
|
||||
headers_obj.addOptions("build_options", default_build_options.step(b));
|
||||
}
|
||||
|
||||
{
|
||||
const headers_step = b.step("string-bench", "Build string bench");
|
||||
var headers_obj = b.addExecutable(.{
|
||||
|
||||
79
src/bun.js/api/js_brotli.zig
Normal file
79
src/bun.js/api/js_brotli.zig
Normal file
@@ -0,0 +1,79 @@
|
||||
const Bun = @This();
|
||||
const default_allocator = @import("root").bun.default_allocator;
|
||||
const bun = @import("root").bun;
|
||||
const JSC = bun.JSC;
|
||||
const Environment = bun.Environment;
|
||||
const NetworkThread = @import("root").bun.HTTP.NetworkThread;
|
||||
const Global = bun.Global;
|
||||
const strings = bun.strings;
|
||||
const string = bun.string;
|
||||
const Output = @import("root").bun.Output;
|
||||
const MutableString = @import("root").bun.MutableString;
|
||||
const std = @import("std");
|
||||
const Allocator = std.mem.Allocator;
|
||||
const brotli = bun.brotli;
|
||||
|
||||
pub const Brotli = struct {
|
||||
fn brotli_alloc_func(ctx: ?*anyopaque, size: usize) callconv(.C) ?*anyopaque {
|
||||
_ = ctx;
|
||||
return bun.Mimalloc.mi_malloc(size);
|
||||
}
|
||||
fn brotli_free_func(ctx: ?*anyopaque, ptr: ?*anyopaque) callconv(.C) void {
|
||||
_ = ctx;
|
||||
return bun.Mimalloc.mi_free(ptr);
|
||||
}
|
||||
|
||||
pub const Options = struct {
|
||||
pub fn fromJS(globalObject: *JSC.JSGlobalObject, value: JSC.JSValue, comptime StateType: type) !*StateType {
|
||||
if (!value.isObject()) {
|
||||
globalObject.throwInvalidArguments("Expected options to be an object", .{});
|
||||
return error.JSError;
|
||||
}
|
||||
var state = if (comptime StateType == brotli.BrotliDecoderState) brotli.BrotliDecoderCreateInstance(brotli_alloc_func, brotli_free_func, null) else brotli.BrotliEncoderCreateInstance(brotli_alloc_func, brotli_free_func, null);
|
||||
errdefer {
|
||||
if (comptime StateType == brotli.BrotliDecoderState) {
|
||||
brotli.BrotliDecoderDestroyInstance(state);
|
||||
} else {
|
||||
brotli.BrotliEncoderDestroyInstance(state);
|
||||
}
|
||||
}
|
||||
const setParamter = if (comptime StateType == brotli.BrotliDecoderState)
|
||||
brotli.BrotliDecoderSetParameter
|
||||
else
|
||||
brotli.BrotliEncoderSetParameter;
|
||||
|
||||
// flush <integer> Default: zlib.constants.BROTLI_OPERATION_PROCESS
|
||||
var flush_value = brotli.BROTLI_OPERATION_PROCESS;
|
||||
if (try value.getOptional(globalObject, "flush", u32)) |flushy| {
|
||||
flush_value = flushy;
|
||||
}
|
||||
|
||||
if (setParamter(state, .flush, flush_value) == 0) {
|
||||
globalObject.throwInvalidArguments("Invalid flush value", .{});
|
||||
return error.JSError;
|
||||
}
|
||||
|
||||
// finishFlush <integer> Default: zlib.constants.BROTLI_OPERATION_FINISH
|
||||
var finishFlush_value = brotli.BROTLI_OPERATION_FINISH;
|
||||
if (try value.getOptional(globalObject, "finishFlush", u32)) |finishFlushy| {
|
||||
finishFlush_value = finishFlushy;
|
||||
}
|
||||
|
||||
if (setParamter(state, .finishFlush, flush_value) == 0) {
|
||||
globalObject.throwInvalidArguments("Invalid finishFlush value", .{});
|
||||
return error.JSError;
|
||||
}
|
||||
|
||||
// chunkSize <integer> Default: 16 * 1024
|
||||
var chunkSize_value = 16 * 1024;
|
||||
if (try value.getOptional(globalObject, "chunkSize", u32)) |chunkSizey| {
|
||||
chunkSize_value = chunkSizey;
|
||||
}
|
||||
|
||||
// params <Object> Key-value object containing indexed Brotli parameters.
|
||||
|
||||
// maxOutputLength <integer> Limits output size when using convenience methods. Default: buffer.kMaxLength
|
||||
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -1784,6 +1784,16 @@ pub const ArrayBuffer = extern struct {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn createFromLength(globalThis: *JSC.JSGlobalObject, len: usize, comptime kind: BinaryType) JSValue {
|
||||
JSC.markBinding(@src());
|
||||
return switch (comptime kind) {
|
||||
.Uint8Array => Bun__createUint8ArrayForCopy(globalThis, null, len, false),
|
||||
.Buffer => Bun__createUint8ArrayForCopy(globalThis, null, len, true),
|
||||
.ArrayBuffer => Bun__createArrayBufferForCopy(globalThis, null, len),
|
||||
else => @compileError("Not implemented yet"),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn createEmpty(globalThis: *JSC.JSGlobalObject, comptime kind: JSC.JSValue.JSType) JSValue {
|
||||
JSC.markBinding(@src());
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <JavaScriptCore/WeakMapImplInlines.h>
|
||||
#include <JavaScriptCore/FunctionPrototype.h>
|
||||
#include <JavaScriptCore/DateInstance.h>
|
||||
#include <JavaScriptCore/JSInternalFieldObjectImplInlines.h>
|
||||
|
||||
namespace Bun {
|
||||
|
||||
@@ -1437,19 +1438,3 @@ JSC_DEFINE_HOST_FUNCTION(jsMockFunctionWithImplementation, (JSC::JSGlobalObject
|
||||
return JSC::JSValue::encode(jsUndefined());
|
||||
}
|
||||
} // namespace Bun
|
||||
|
||||
namespace JSC {
|
||||
|
||||
template<unsigned passedNumberOfInternalFields>
|
||||
template<typename Visitor>
|
||||
void JSInternalFieldObjectImpl<passedNumberOfInternalFields>::visitChildrenImpl(JSCell* cell, Visitor& visitor)
|
||||
{
|
||||
auto* thisObject = jsCast<JSInternalFieldObjectImpl*>(cell);
|
||||
ASSERT_GC_OBJECT_INHERITS(thisObject, info());
|
||||
Base::visitChildren(thisObject, visitor);
|
||||
visitor.appendValues(thisObject->m_internalFields, numberOfInternalFields);
|
||||
}
|
||||
|
||||
DEFINE_VISIT_CHILDREN_WITH_MODIFIER(template<unsigned passedNumberOfInternalFields>, JSInternalFieldObjectImpl<passedNumberOfInternalFields>);
|
||||
|
||||
} // namespace JSC
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
296
src/bun.js/bindings/JSSink.h
generated
296
src/bun.js/bindings/JSSink.h
generated
@@ -1,6 +1,6 @@
|
||||
|
||||
// AUTO-GENERATED FILE. DO NOT EDIT.
|
||||
// Generated by 'make generate-sink' at 2023-07-17T20:32:20.222Z
|
||||
// Generated by 'make generate-sink' at 2023-07-18T09:07:30.318Z
|
||||
//
|
||||
#pragma once
|
||||
|
||||
@@ -605,6 +605,300 @@ public:
|
||||
|
||||
JSC_DECLARE_CUSTOM_GETTER(functionHTTPSResponseSink__getter);
|
||||
|
||||
class JSBrotliDecompressorSinkConstructor final : public JSC::InternalFunction {
|
||||
public:
|
||||
using Base = JSC::InternalFunction;
|
||||
static JSBrotliDecompressorSinkConstructor* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, JSC::JSObject* prototype);
|
||||
static constexpr SinkID Sink = SinkID::BrotliDecompressorSink;
|
||||
|
||||
static constexpr unsigned StructureFlags = Base::StructureFlags;
|
||||
static constexpr bool needsDestruction = false;
|
||||
|
||||
DECLARE_EXPORT_INFO;
|
||||
template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
|
||||
{
|
||||
if constexpr (mode == JSC::SubspaceAccess::Concurrently)
|
||||
return nullptr;
|
||||
return WebCore::subspaceForImpl<JSBrotliDecompressorSinkConstructor, WebCore::UseCustomHeapCellType::No>(
|
||||
vm,
|
||||
[](auto& spaces) { return spaces.m_clientSubspaceForJSSinkConstructor.get(); },
|
||||
[](auto& spaces, auto&& space) { spaces.m_clientSubspaceForJSSinkConstructor = std::forward<decltype(space)>(space); },
|
||||
[](auto& spaces) { return spaces.m_subspaceForJSSinkConstructor.get(); },
|
||||
[](auto& spaces, auto&& space) { spaces.m_subspaceForJSSinkConstructor = std::forward<decltype(space)>(space); });
|
||||
}
|
||||
|
||||
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
|
||||
{
|
||||
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::InternalFunctionType, StructureFlags), info());
|
||||
}
|
||||
void initializeProperties(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSObject* prototype);
|
||||
|
||||
// Must be defined for each specialization class.
|
||||
static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES construct(JSC::JSGlobalObject*, JSC::CallFrame*);
|
||||
|
||||
private:
|
||||
JSBrotliDecompressorSinkConstructor(JSC::VM& vm, JSC::Structure* structure, JSC::NativeFunction nativeFunction)
|
||||
: Base(vm, structure, nativeFunction, nativeFunction)
|
||||
|
||||
{
|
||||
}
|
||||
|
||||
void finishCreation(JSC::VM&, JSC::JSGlobalObject* globalObject, JSC::JSObject* prototype);
|
||||
};
|
||||
|
||||
class JSBrotliDecompressorSink final : public JSC::JSDestructibleObject {
|
||||
public:
|
||||
using Base = JSC::JSDestructibleObject;
|
||||
static JSBrotliDecompressorSink* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* sinkPtr);
|
||||
static constexpr SinkID Sink = SinkID::BrotliDecompressorSink;
|
||||
|
||||
DECLARE_EXPORT_INFO;
|
||||
template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
|
||||
{
|
||||
if constexpr (mode == JSC::SubspaceAccess::Concurrently)
|
||||
return nullptr;
|
||||
return WebCore::subspaceForImpl<JSBrotliDecompressorSink, WebCore::UseCustomHeapCellType::No>(
|
||||
vm,
|
||||
[](auto& spaces) { return spaces.m_clientSubspaceForJSSink.get(); },
|
||||
[](auto& spaces, auto&& space) { spaces.m_clientSubspaceForJSSink = std::forward<decltype(space)>(space); },
|
||||
[](auto& spaces) { return spaces.m_subspaceForJSSink.get(); },
|
||||
[](auto& spaces, auto&& space) { spaces.m_subspaceForJSSink = std::forward<decltype(space)>(space); });
|
||||
}
|
||||
|
||||
static void destroy(JSC::JSCell*);
|
||||
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
|
||||
{
|
||||
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
|
||||
}
|
||||
|
||||
static JSObject* createPrototype(VM& vm, JSDOMGlobalObject& globalObject);
|
||||
|
||||
~JSBrotliDecompressorSink();
|
||||
|
||||
void* wrapped() const { return m_sinkPtr; }
|
||||
DECLARE_VISIT_CHILDREN;
|
||||
|
||||
void detach()
|
||||
{
|
||||
m_sinkPtr = nullptr;
|
||||
}
|
||||
|
||||
static void analyzeHeap(JSCell*, JSC::HeapAnalyzer&);
|
||||
|
||||
void ref();
|
||||
void unref();
|
||||
|
||||
void* m_sinkPtr;
|
||||
int m_refCount { 1 };
|
||||
|
||||
JSBrotliDecompressorSink(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
|
||||
: Base(vm, structure)
|
||||
{
|
||||
m_sinkPtr = sinkPtr;
|
||||
}
|
||||
|
||||
void finishCreation(JSC::VM&);
|
||||
};
|
||||
|
||||
class JSReadableBrotliDecompressorSinkController final : public JSC::JSDestructibleObject {
|
||||
public:
|
||||
using Base = JSC::JSDestructibleObject;
|
||||
static JSReadableBrotliDecompressorSinkController* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* sinkPtr);
|
||||
static constexpr SinkID Sink = SinkID::BrotliDecompressorSink;
|
||||
|
||||
DECLARE_EXPORT_INFO;
|
||||
template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
|
||||
{
|
||||
if constexpr (mode == JSC::SubspaceAccess::Concurrently)
|
||||
return nullptr;
|
||||
return WebCore::subspaceForImpl<JSReadableBrotliDecompressorSinkController, WebCore::UseCustomHeapCellType::No>(
|
||||
vm,
|
||||
[](auto& spaces) { return spaces.m_clientSubspaceForJSSinkController.get(); },
|
||||
[](auto& spaces, auto&& space) { spaces.m_clientSubspaceForJSSinkController = std::forward<decltype(space)>(space); },
|
||||
[](auto& spaces) { return spaces.m_subspaceForJSSinkController.get(); },
|
||||
[](auto& spaces, auto&& space) { spaces.m_subspaceForJSSinkController = std::forward<decltype(space)>(space); });
|
||||
}
|
||||
|
||||
static void destroy(JSC::JSCell*);
|
||||
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
|
||||
{
|
||||
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
|
||||
}
|
||||
static JSObject* createPrototype(VM& vm, JSDOMGlobalObject& globalObject);
|
||||
|
||||
~JSReadableBrotliDecompressorSinkController();
|
||||
|
||||
void* wrapped() const { return m_sinkPtr; }
|
||||
void detach();
|
||||
|
||||
void start(JSC::JSGlobalObject* globalObject, JSC::JSValue readableStream, JSC::JSFunction* onPull, JSC::JSFunction* onClose);
|
||||
DECLARE_VISIT_CHILDREN;
|
||||
|
||||
static void analyzeHeap(JSCell*, JSC::HeapAnalyzer&);
|
||||
|
||||
void* m_sinkPtr;
|
||||
mutable WriteBarrier<JSC::JSFunction> m_onPull;
|
||||
mutable WriteBarrier<JSC::JSFunction> m_onClose;
|
||||
mutable JSC::Weak<JSObject> m_weakReadableStream;
|
||||
|
||||
JSReadableBrotliDecompressorSinkController(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
|
||||
: Base(vm, structure)
|
||||
{
|
||||
m_sinkPtr = sinkPtr;
|
||||
}
|
||||
|
||||
void finishCreation(JSC::VM&);
|
||||
};
|
||||
|
||||
JSC_DECLARE_CUSTOM_GETTER(functionBrotliDecompressorSink__getter);
|
||||
|
||||
class JSBrotliCompressorSinkConstructor final : public JSC::InternalFunction {
|
||||
public:
|
||||
using Base = JSC::InternalFunction;
|
||||
static JSBrotliCompressorSinkConstructor* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, JSC::JSObject* prototype);
|
||||
static constexpr SinkID Sink = SinkID::BrotliCompressorSink;
|
||||
|
||||
static constexpr unsigned StructureFlags = Base::StructureFlags;
|
||||
static constexpr bool needsDestruction = false;
|
||||
|
||||
DECLARE_EXPORT_INFO;
|
||||
template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
|
||||
{
|
||||
if constexpr (mode == JSC::SubspaceAccess::Concurrently)
|
||||
return nullptr;
|
||||
return WebCore::subspaceForImpl<JSBrotliCompressorSinkConstructor, WebCore::UseCustomHeapCellType::No>(
|
||||
vm,
|
||||
[](auto& spaces) { return spaces.m_clientSubspaceForJSSinkConstructor.get(); },
|
||||
[](auto& spaces, auto&& space) { spaces.m_clientSubspaceForJSSinkConstructor = std::forward<decltype(space)>(space); },
|
||||
[](auto& spaces) { return spaces.m_subspaceForJSSinkConstructor.get(); },
|
||||
[](auto& spaces, auto&& space) { spaces.m_subspaceForJSSinkConstructor = std::forward<decltype(space)>(space); });
|
||||
}
|
||||
|
||||
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
|
||||
{
|
||||
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::InternalFunctionType, StructureFlags), info());
|
||||
}
|
||||
void initializeProperties(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSObject* prototype);
|
||||
|
||||
// Must be defined for each specialization class.
|
||||
static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES construct(JSC::JSGlobalObject*, JSC::CallFrame*);
|
||||
|
||||
private:
|
||||
JSBrotliCompressorSinkConstructor(JSC::VM& vm, JSC::Structure* structure, JSC::NativeFunction nativeFunction)
|
||||
: Base(vm, structure, nativeFunction, nativeFunction)
|
||||
|
||||
{
|
||||
}
|
||||
|
||||
void finishCreation(JSC::VM&, JSC::JSGlobalObject* globalObject, JSC::JSObject* prototype);
|
||||
};
|
||||
|
||||
class JSBrotliCompressorSink final : public JSC::JSDestructibleObject {
|
||||
public:
|
||||
using Base = JSC::JSDestructibleObject;
|
||||
static JSBrotliCompressorSink* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* sinkPtr);
|
||||
static constexpr SinkID Sink = SinkID::BrotliCompressorSink;
|
||||
|
||||
DECLARE_EXPORT_INFO;
|
||||
template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
|
||||
{
|
||||
if constexpr (mode == JSC::SubspaceAccess::Concurrently)
|
||||
return nullptr;
|
||||
return WebCore::subspaceForImpl<JSBrotliCompressorSink, WebCore::UseCustomHeapCellType::No>(
|
||||
vm,
|
||||
[](auto& spaces) { return spaces.m_clientSubspaceForJSSink.get(); },
|
||||
[](auto& spaces, auto&& space) { spaces.m_clientSubspaceForJSSink = std::forward<decltype(space)>(space); },
|
||||
[](auto& spaces) { return spaces.m_subspaceForJSSink.get(); },
|
||||
[](auto& spaces, auto&& space) { spaces.m_subspaceForJSSink = std::forward<decltype(space)>(space); });
|
||||
}
|
||||
|
||||
static void destroy(JSC::JSCell*);
|
||||
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
|
||||
{
|
||||
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
|
||||
}
|
||||
|
||||
static JSObject* createPrototype(VM& vm, JSDOMGlobalObject& globalObject);
|
||||
|
||||
~JSBrotliCompressorSink();
|
||||
|
||||
void* wrapped() const { return m_sinkPtr; }
|
||||
DECLARE_VISIT_CHILDREN;
|
||||
|
||||
void detach()
|
||||
{
|
||||
m_sinkPtr = nullptr;
|
||||
}
|
||||
|
||||
static void analyzeHeap(JSCell*, JSC::HeapAnalyzer&);
|
||||
|
||||
void ref();
|
||||
void unref();
|
||||
|
||||
void* m_sinkPtr;
|
||||
int m_refCount { 1 };
|
||||
|
||||
JSBrotliCompressorSink(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
|
||||
: Base(vm, structure)
|
||||
{
|
||||
m_sinkPtr = sinkPtr;
|
||||
}
|
||||
|
||||
void finishCreation(JSC::VM&);
|
||||
};
|
||||
|
||||
class JSReadableBrotliCompressorSinkController final : public JSC::JSDestructibleObject {
|
||||
public:
|
||||
using Base = JSC::JSDestructibleObject;
|
||||
static JSReadableBrotliCompressorSinkController* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, void* sinkPtr);
|
||||
static constexpr SinkID Sink = SinkID::BrotliCompressorSink;
|
||||
|
||||
DECLARE_EXPORT_INFO;
|
||||
template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
|
||||
{
|
||||
if constexpr (mode == JSC::SubspaceAccess::Concurrently)
|
||||
return nullptr;
|
||||
return WebCore::subspaceForImpl<JSReadableBrotliCompressorSinkController, WebCore::UseCustomHeapCellType::No>(
|
||||
vm,
|
||||
[](auto& spaces) { return spaces.m_clientSubspaceForJSSinkController.get(); },
|
||||
[](auto& spaces, auto&& space) { spaces.m_clientSubspaceForJSSinkController = std::forward<decltype(space)>(space); },
|
||||
[](auto& spaces) { return spaces.m_subspaceForJSSinkController.get(); },
|
||||
[](auto& spaces, auto&& space) { spaces.m_subspaceForJSSinkController = std::forward<decltype(space)>(space); });
|
||||
}
|
||||
|
||||
static void destroy(JSC::JSCell*);
|
||||
static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
|
||||
{
|
||||
return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
|
||||
}
|
||||
static JSObject* createPrototype(VM& vm, JSDOMGlobalObject& globalObject);
|
||||
|
||||
~JSReadableBrotliCompressorSinkController();
|
||||
|
||||
void* wrapped() const { return m_sinkPtr; }
|
||||
void detach();
|
||||
|
||||
void start(JSC::JSGlobalObject* globalObject, JSC::JSValue readableStream, JSC::JSFunction* onPull, JSC::JSFunction* onClose);
|
||||
DECLARE_VISIT_CHILDREN;
|
||||
|
||||
static void analyzeHeap(JSCell*, JSC::HeapAnalyzer&);
|
||||
|
||||
void* m_sinkPtr;
|
||||
mutable WriteBarrier<JSC::JSFunction> m_onPull;
|
||||
mutable WriteBarrier<JSC::JSFunction> m_onClose;
|
||||
mutable JSC::Weak<JSObject> m_weakReadableStream;
|
||||
|
||||
JSReadableBrotliCompressorSinkController(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
|
||||
: Base(vm, structure)
|
||||
{
|
||||
m_sinkPtr = sinkPtr;
|
||||
}
|
||||
|
||||
void finishCreation(JSC::VM&);
|
||||
};
|
||||
|
||||
JSC_DECLARE_CUSTOM_GETTER(functionBrotliCompressorSink__getter);
|
||||
|
||||
JSObject* createJSSinkPrototype(JSC::VM& vm, JSC::JSGlobalObject* globalObject, WebCore::SinkID sinkID);
|
||||
JSObject* createJSSinkControllerPrototype(JSC::VM& vm, JSC::JSGlobalObject* globalObject, WebCore::SinkID sinkID);
|
||||
Structure* createJSSinkControllerStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, WebCore::SinkID sinkID);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Automatically generated from src/bun.js/bindings/JSSink.cpp using /home/cirospaciari/Repos/bun/src/bun.js/WebKit/Source/JavaScriptCore/create_hash_table. DO NOT EDIT!
|
||||
// Automatically generated from src/bun.js/bindings/JSSink.cpp using /Users/jarred/Code/bun/src/bun.js/WebKit/Source/JavaScriptCore/create_hash_table. DO NOT EDIT!
|
||||
|
||||
|
||||
|
||||
@@ -319,3 +319,163 @@ static const struct HashTable JSReadableHTTPSResponseSinkControllerPrototypeTabl
|
||||
{ 5, 15, false, nullptr, JSReadableHTTPSResponseSinkControllerPrototypeTableValues, JSReadableHTTPSResponseSinkControllerPrototypeTableIndex };
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static const struct CompactHashIndex JSBrotliDecompressorSinkPrototypeTableIndex[19] = {
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ 6, -1 },
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ 0, 16 },
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ 5, -1 },
|
||||
{ 4, -1 },
|
||||
{ 1, 17 },
|
||||
{ 2, 18 },
|
||||
{ 3, -1 },
|
||||
};
|
||||
|
||||
static const struct HashTableValue JSBrotliDecompressorSinkPrototypeTableValues[7] = {
|
||||
{ "close"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BrotliDecompressorSink__doClose, 0 } },
|
||||
{ "flush"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BrotliDecompressorSink__flush, 1 } },
|
||||
{ "end"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BrotliDecompressorSink__end, 0 } },
|
||||
{ "start"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BrotliDecompressorSink__start, 1 } },
|
||||
{ "write"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BrotliDecompressorSink__write, 1 } },
|
||||
{ "ref"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BrotliDecompressorSink__ref, 0 } },
|
||||
{ "unref"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BrotliDecompressorSink__unref, 0 } },
|
||||
};
|
||||
|
||||
static const struct HashTable JSBrotliDecompressorSinkPrototypeTable =
|
||||
{ 7, 15, false, nullptr, JSBrotliDecompressorSinkPrototypeTableValues, JSBrotliDecompressorSinkPrototypeTableIndex };
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static const struct CompactHashIndex JSReadableBrotliDecompressorSinkControllerPrototypeTableIndex[19] = {
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ 0, 16 },
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ 4, -1 },
|
||||
{ 1, 17 },
|
||||
{ 2, 18 },
|
||||
{ 3, -1 },
|
||||
};
|
||||
|
||||
static const struct HashTableValue JSReadableBrotliDecompressorSinkControllerPrototypeTableValues[5] = {
|
||||
{ "close"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, JSReadableBrotliDecompressorSinkController__close, 0 } },
|
||||
{ "flush"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BrotliDecompressorSink__flush, 1 } },
|
||||
{ "end"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, JSReadableBrotliDecompressorSinkController__end, 0 } },
|
||||
{ "start"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BrotliDecompressorSink__start, 1 } },
|
||||
{ "write"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BrotliDecompressorSink__write, 1 } },
|
||||
};
|
||||
|
||||
static const struct HashTable JSReadableBrotliDecompressorSinkControllerPrototypeTable =
|
||||
{ 5, 15, false, nullptr, JSReadableBrotliDecompressorSinkControllerPrototypeTableValues, JSReadableBrotliDecompressorSinkControllerPrototypeTableIndex };
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static const struct CompactHashIndex JSBrotliCompressorSinkPrototypeTableIndex[19] = {
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ 6, -1 },
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ 0, 16 },
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ 5, -1 },
|
||||
{ 4, -1 },
|
||||
{ 1, 17 },
|
||||
{ 2, 18 },
|
||||
{ 3, -1 },
|
||||
};
|
||||
|
||||
static const struct HashTableValue JSBrotliCompressorSinkPrototypeTableValues[7] = {
|
||||
{ "close"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BrotliCompressorSink__doClose, 0 } },
|
||||
{ "flush"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BrotliCompressorSink__flush, 1 } },
|
||||
{ "end"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BrotliCompressorSink__end, 0 } },
|
||||
{ "start"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BrotliCompressorSink__start, 1 } },
|
||||
{ "write"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BrotliCompressorSink__write, 1 } },
|
||||
{ "ref"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BrotliCompressorSink__ref, 0 } },
|
||||
{ "unref"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BrotliCompressorSink__unref, 0 } },
|
||||
};
|
||||
|
||||
static const struct HashTable JSBrotliCompressorSinkPrototypeTable =
|
||||
{ 7, 15, false, nullptr, JSBrotliCompressorSinkPrototypeTableValues, JSBrotliCompressorSinkPrototypeTableIndex };
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static const struct CompactHashIndex JSReadableBrotliCompressorSinkControllerPrototypeTableIndex[19] = {
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ 0, 16 },
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ -1, -1 },
|
||||
{ 4, -1 },
|
||||
{ 1, 17 },
|
||||
{ 2, 18 },
|
||||
{ 3, -1 },
|
||||
};
|
||||
|
||||
static const struct HashTableValue JSReadableBrotliCompressorSinkControllerPrototypeTableValues[5] = {
|
||||
{ "close"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, JSReadableBrotliCompressorSinkController__close, 0 } },
|
||||
{ "flush"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BrotliCompressorSink__flush, 1 } },
|
||||
{ "end"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, JSReadableBrotliCompressorSinkController__end, 0 } },
|
||||
{ "start"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BrotliCompressorSink__start, 1 } },
|
||||
{ "write"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BrotliCompressorSink__write, 1 } },
|
||||
};
|
||||
|
||||
static const struct HashTable JSReadableBrotliCompressorSinkControllerPrototypeTable =
|
||||
{ 5, 15, false, nullptr, JSReadableBrotliCompressorSinkControllerPrototypeTableValues, JSReadableBrotliCompressorSinkControllerPrototypeTableIndex };
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include "JavaScriptCore/JSNativeStdFunction.h"
|
||||
#include "JavaScriptCore/JSCJSValueInlines.h"
|
||||
#include "JavaScriptCore/JSInternalPromise.h"
|
||||
#include "JavaScriptCore/JSInternalFieldObjectImpl.h"
|
||||
|
||||
#include "ZigSourceProvider.h"
|
||||
|
||||
@@ -36,11 +35,12 @@
|
||||
#include "../modules/TTYModule.h"
|
||||
#include "node_util_types.h"
|
||||
#include "CommonJSModuleRecord.h"
|
||||
#include <JavaScriptCore/JSModuleLoader.h>
|
||||
#include <JavaScriptCore/Completion.h>
|
||||
#include <JavaScriptCore/JSModuleNamespaceObject.h>
|
||||
#include <JavaScriptCore/JSMap.h>
|
||||
#include <JavaScriptCore/JSMapInlines.h>
|
||||
#include "JavaScriptCore/JSModuleLoader.h"
|
||||
#include "JavaScriptCore/Completion.h"
|
||||
#include "JavaScriptCore/JSModuleNamespaceObject.h"
|
||||
#include "JavaScriptCore/JSMap.h"
|
||||
#include "JavaScriptCore/JSMapInlines.h"
|
||||
#include "JavaScriptCore/JSInternalFieldObjectImplInlines.h"
|
||||
|
||||
namespace Bun {
|
||||
using namespace Zig;
|
||||
@@ -690,18 +690,3 @@ JSValue fetchSourceCodeAsync(
|
||||
return fetchSourceCode<true>(globalObject, res, specifier, referrer);
|
||||
}
|
||||
}
|
||||
namespace JSC {
|
||||
|
||||
template<unsigned passedNumberOfInternalFields>
|
||||
template<typename Visitor>
|
||||
void JSInternalFieldObjectImpl<passedNumberOfInternalFields>::visitChildrenImpl(JSCell* cell, Visitor& visitor)
|
||||
{
|
||||
auto* thisObject = jsCast<JSInternalFieldObjectImpl*>(cell);
|
||||
ASSERT_GC_OBJECT_INHERITS(thisObject, info());
|
||||
Base::visitChildren(thisObject, visitor);
|
||||
visitor.appendValues(thisObject->m_internalFields, numberOfInternalFields);
|
||||
}
|
||||
|
||||
DEFINE_VISIT_CHILDREN_WITH_MODIFIER(template<unsigned passedNumberOfInternalFields>, JSInternalFieldObjectImpl<passedNumberOfInternalFields>);
|
||||
|
||||
} // namespace JSC
|
||||
|
||||
@@ -9,9 +9,11 @@ enum SinkID : uint8_t {
|
||||
HTMLRewriterSink = 3,
|
||||
HTTPResponseSink = 4,
|
||||
HTTPSResponseSink = 5,
|
||||
BrotliDecompressorSink = 6,
|
||||
BrotliCompressorSink = 7,
|
||||
|
||||
};
|
||||
static constexpr unsigned numberOfSinkIDs
|
||||
= 6;
|
||||
= 8;
|
||||
|
||||
}
|
||||
@@ -1390,7 +1390,7 @@ extern "C" JSC__JSValue Bun__createArrayBufferForCopy(JSC::JSGlobalObject* globa
|
||||
return JSC::JSValue::encode(JSC::JSValue {});
|
||||
}
|
||||
|
||||
if (len > 0)
|
||||
if (len > 0 && ptr)
|
||||
memcpy(arrayBuffer->data(), ptr, len);
|
||||
|
||||
RELEASE_AND_RETURN(scope, JSValue::encode(JSC::JSArrayBuffer::create(globalObject->vm(), globalObject->arrayBufferStructure(JSC::ArrayBufferSharingMode::Default), WTFMove(arrayBuffer))));
|
||||
@@ -1409,7 +1409,7 @@ extern "C" JSC__JSValue Bun__createUint8ArrayForCopy(JSC::JSGlobalObject* global
|
||||
return JSC::JSValue::encode(JSC::JSValue {});
|
||||
}
|
||||
|
||||
if (len > 0)
|
||||
if (len > 0 && ptr)
|
||||
memcpy(array->vector(), ptr, len);
|
||||
|
||||
RELEASE_AND_RETURN(scope, JSValue::encode(array));
|
||||
@@ -3292,6 +3292,26 @@ void GlobalObject::finishCreation(VM& vm)
|
||||
init.setConstructor(constructor);
|
||||
});
|
||||
|
||||
m_JSBrotliDecompressorSinkClassStructure.initLater(
|
||||
[](LazyClassStructure::Initializer& init) {
|
||||
auto* prototype = createJSSinkPrototype(init.vm, init.global, WebCore::SinkID::BrotliDecompressorSink);
|
||||
auto* structure = JSBrotliDecompressorSink::createStructure(init.vm, init.global, prototype);
|
||||
auto* constructor = JSBrotliDecompressorSinkConstructor::create(init.vm, init.global, JSBrotliDecompressorSinkConstructor::createStructure(init.vm, init.global, init.global->functionPrototype()), jsCast<JSObject*>(prototype));
|
||||
init.setPrototype(prototype);
|
||||
init.setStructure(structure);
|
||||
init.setConstructor(constructor);
|
||||
});
|
||||
|
||||
m_JSBrotliCompressorSinkClassStructure.initLater(
|
||||
[](LazyClassStructure::Initializer& init) {
|
||||
auto* prototype = createJSSinkPrototype(init.vm, init.global, WebCore::SinkID::BrotliCompressorSink);
|
||||
auto* structure = JSBrotliCompressorSink::createStructure(init.vm, init.global, prototype);
|
||||
auto* constructor = JSBrotliCompressorSinkConstructor::create(init.vm, init.global, JSBrotliCompressorSinkConstructor::createStructure(init.vm, init.global, init.global->functionPrototype()), jsCast<JSObject*>(prototype));
|
||||
init.setPrototype(prototype);
|
||||
init.setStructure(structure);
|
||||
init.setConstructor(constructor);
|
||||
});
|
||||
|
||||
m_JSArrayBufferSinkClassStructure.initLater(
|
||||
[](LazyClassStructure::Initializer& init) {
|
||||
auto* prototype = createJSSinkPrototype(init.vm, init.global, WebCore::SinkID::ArrayBufferSink);
|
||||
@@ -4215,6 +4235,18 @@ void GlobalObject::installAPIGlobals(JSClassRef* globals, int count, JSC::VM& vm
|
||||
JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly);
|
||||
}
|
||||
|
||||
{
|
||||
JSC::Identifier identifier = JSC::Identifier::fromString(vm, "BrotliDecompressorSink"_s);
|
||||
object->putDirectCustomAccessor(vm, identifier, JSC::CustomGetterSetter::create(vm, functionBrotliDecompressorSink__getter, nullptr),
|
||||
JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly);
|
||||
}
|
||||
|
||||
{
|
||||
JSC::Identifier identifier = JSC::Identifier::fromString(vm, "BrotliCompressorSink"_s);
|
||||
object->putDirectCustomAccessor(vm, identifier, JSC::CustomGetterSetter::create(vm, functionBrotliCompressorSink__getter, nullptr),
|
||||
JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly);
|
||||
}
|
||||
|
||||
{
|
||||
JSC::Identifier identifier = JSC::Identifier::fromString(vm, "nanoseconds"_s);
|
||||
object->putDirectNativeFunction(vm, this, identifier, 1, functionBunNanoseconds, ImplementationVisibility::Public, NoIntrinsic,
|
||||
@@ -4415,6 +4447,8 @@ void GlobalObject::visitChildrenImpl(JSCell* cell, Visitor& visitor)
|
||||
thisObject->m_JSFileSinkClassStructure.visit(visitor);
|
||||
thisObject->m_JSHTTPResponseSinkClassStructure.visit(visitor);
|
||||
thisObject->m_JSHTTPSResponseSinkClassStructure.visit(visitor);
|
||||
thisObject->m_JSBrotliDecompressorSinkClassStructure.visit(visitor);
|
||||
thisObject->m_JSBrotliCompressorSinkClassStructure.visit(visitor);
|
||||
thisObject->m_JSReadableStateClassStructure.visit(visitor);
|
||||
thisObject->m_JSStringDecoderClassStructure.visit(visitor);
|
||||
thisObject->m_NapiClassStructure.visit(visitor);
|
||||
@@ -4430,6 +4464,8 @@ void GlobalObject::visitChildrenImpl(JSCell* cell, Visitor& visitor)
|
||||
thisObject->m_JSArrayBufferControllerPrototype.visit(visitor);
|
||||
thisObject->m_JSFileSinkControllerPrototype.visit(visitor);
|
||||
thisObject->m_JSHTTPSResponseControllerPrototype.visit(visitor);
|
||||
thisObject->m_JSBrotliDecompressorSinkControllerPrototype.visit(visitor);
|
||||
thisObject->m_JSBrotliCompressorSinkControllerPrototype.visit(visitor);
|
||||
thisObject->m_navigatorObject.visit(visitor);
|
||||
thisObject->m_nativeMicrotaskTrampoline.visit(visitor);
|
||||
thisObject->m_performanceObject.visit(visitor);
|
||||
|
||||
@@ -205,6 +205,16 @@ public:
|
||||
JSC::Structure* FFIFunctionStructure() { return m_JSFFIFunctionStructure.getInitializedOnMainThread(this); }
|
||||
JSC::Structure* NapiClassStructure() { return m_NapiClassStructure.getInitializedOnMainThread(this); }
|
||||
|
||||
JSC::Structure* BrotliDecompressorSinkStructure() { return m_JSBrotliDecompressorSinkClassStructure.getInitializedOnMainThread(this); }
|
||||
JSC::JSObject* BrotliDecompressorSink() { return m_JSBrotliDecompressorSinkClassStructure.constructorInitializedOnMainThread(this); }
|
||||
JSC::JSValue BrotliDecompressorSinkPrototype() { return m_JSBrotliDecompressorSinkClassStructure.prototypeInitializedOnMainThread(this); }
|
||||
JSC::JSValue JSReadableBrotliDecompressorSinkControllerPrototype() { return m_JSBrotliDecompressorSinkControllerPrototype.getInitializedOnMainThread(this); }
|
||||
|
||||
JSC::Structure* BrotliCompressorSinkStructure() { return m_JSBrotliCompressorSinkClassStructure.getInitializedOnMainThread(this); }
|
||||
JSC::JSObject* BrotliCompressorSink() { return m_JSBrotliCompressorSinkClassStructure.constructorInitializedOnMainThread(this); }
|
||||
JSC::JSValue BrotliCompressorSinkPrototype() { return m_JSBrotliCompressorSinkClassStructure.prototypeInitializedOnMainThread(this); }
|
||||
JSC::JSValue JSReadableBrotliCompressorSinkControllerPrototype() { return m_JSBrotliCompressorSinkControllerPrototype.getInitializedOnMainThread(this); }
|
||||
|
||||
JSC::Structure* FileSinkStructure() { return m_JSFileSinkClassStructure.getInitializedOnMainThread(this); }
|
||||
JSC::JSObject* FileSink() { return m_JSFileSinkClassStructure.constructorInitializedOnMainThread(this); }
|
||||
JSC::JSValue FileSinkPrototype() { return m_JSFileSinkClassStructure.prototypeInitializedOnMainThread(this); }
|
||||
@@ -470,6 +480,8 @@ private:
|
||||
LazyClassStructure m_JSFileSinkClassStructure;
|
||||
LazyClassStructure m_JSHTTPResponseSinkClassStructure;
|
||||
LazyClassStructure m_JSHTTPSResponseSinkClassStructure;
|
||||
LazyClassStructure m_JSBrotliDecompressorSinkClassStructure;
|
||||
LazyClassStructure m_JSBrotliCompressorSinkClassStructure;
|
||||
LazyClassStructure m_JSReadableStateClassStructure;
|
||||
LazyClassStructure m_JSStringDecoderClassStructure;
|
||||
LazyClassStructure m_NapiClassStructure;
|
||||
@@ -498,6 +510,8 @@ private:
|
||||
LazyProperty<JSGlobalObject, JSObject> m_JSArrayBufferControllerPrototype;
|
||||
LazyProperty<JSGlobalObject, JSObject> m_JSFileSinkControllerPrototype;
|
||||
LazyProperty<JSGlobalObject, JSObject> m_JSHTTPSResponseControllerPrototype;
|
||||
LazyProperty<JSGlobalObject, JSObject> m_JSBrotliCompressorSinkControllerPrototype;
|
||||
LazyProperty<JSGlobalObject, JSObject> m_JSBrotliDecompressorSinkControllerPrototype;
|
||||
LazyProperty<JSGlobalObject, JSObject> m_navigatorObject;
|
||||
LazyProperty<JSGlobalObject, JSObject> m_performanceObject;
|
||||
LazyProperty<JSGlobalObject, JSObject> m_primordialsObject;
|
||||
|
||||
@@ -4430,6 +4430,14 @@ pub const JSValue = enum(JSValueReprInt) {
|
||||
globalThis.throwInvalidArguments(property_name ++ " must be a boolean", .{});
|
||||
return error.JSError;
|
||||
},
|
||||
u32 => {
|
||||
if (prop.isNumber()) {
|
||||
return prop.to(u32);
|
||||
}
|
||||
|
||||
globalThis.throwInvalidArguments(property_name ++ " must be a number", .{});
|
||||
return error.JSError;
|
||||
},
|
||||
ZigString.Slice => {
|
||||
if (prop.isString()) {
|
||||
if (return prop.toSliceOrNull(globalThis)) |str| {
|
||||
|
||||
@@ -163,6 +163,8 @@ pub const JSArrayBufferSink = JSC.WebCore.ArrayBufferSink.JSSink;
|
||||
pub const JSHTTPSResponseSink = JSC.WebCore.HTTPSResponseSink.JSSink;
|
||||
pub const JSHTTPResponseSink = JSC.WebCore.HTTPResponseSink.JSSink;
|
||||
pub const JSFileSink = JSC.WebCore.FileSink.JSSink;
|
||||
pub const JSBrotliDecompressorSink = JSC.WebCore.BrotliDecompressorSink.JSSink;
|
||||
pub const JSBrotliCompressorSink = JSC.WebCore.BrotliCompressorSink.JSSink;
|
||||
|
||||
// WebSocket
|
||||
pub const WebSocketHTTPClient = @import("../../http/websocket_http_client.zig").WebSocketHTTPClient;
|
||||
@@ -3404,6 +3406,8 @@ comptime {
|
||||
JSReadableStreamBlob.shim.ref();
|
||||
JSArrayBufferSink.shim.ref();
|
||||
JSHTTPResponseSink.shim.ref();
|
||||
JSBrotliDecompressorSink.shim.ref();
|
||||
JSBrotliCompressorSink.shim.ref();
|
||||
JSHTTPSResponseSink.shim.ref();
|
||||
JSFileSink.shim.ref();
|
||||
JSReadableStreamBytes.shim.ref();
|
||||
|
||||
@@ -182,8 +182,8 @@ extern "C" const size_t Zig__ConsoleClient_object_align_ = alignof(Zig::ConsoleC
|
||||
extern "C" const size_t Bun__Timer_object_size_ = sizeof(Bun__Timer);
|
||||
extern "C" const size_t Bun__Timer_object_align_ = alignof(Bun__Timer);
|
||||
|
||||
const size_t sizes[41] = {sizeof(JSC::JSObject), sizeof(WebCore::DOMURL), sizeof(WebCore::DOMFormData), sizeof(WebCore::FetchHeaders), sizeof(SystemError), sizeof(JSC::JSCell), sizeof(JSC::JSString), sizeof(JSC::JSModuleLoader), sizeof(WebCore::AbortSignal), sizeof(JSC::JSPromise), sizeof(JSC::JSInternalPromise), sizeof(JSC::JSFunction), sizeof(JSC::JSGlobalObject), sizeof(JSC::JSMap), sizeof(JSC::JSValue), sizeof(JSC::Exception), sizeof(JSC::VM), sizeof(JSC::ThrowScope), sizeof(JSC::CatchScope), sizeof(FFI__ptr), sizeof(Reader__u8), sizeof(Reader__u16), sizeof(Reader__u32), sizeof(Reader__ptr), sizeof(Reader__i8), sizeof(Reader__i16), sizeof(Reader__i32), sizeof(Reader__f32), sizeof(Reader__f64), sizeof(Reader__i64), sizeof(Reader__u64), sizeof(Reader__intptr), sizeof(Crypto__getRandomValues), sizeof(Crypto__randomUUID), sizeof(Crypto__timingSafeEqual), sizeof(Zig::GlobalObject), sizeof(Bun__Path), sizeof(ArrayBufferSink), sizeof(HTTPSResponseSink), sizeof(HTTPResponseSink), sizeof(FileSink)};
|
||||
const size_t sizes[43] = {sizeof(JSC::JSObject), sizeof(WebCore::DOMURL), sizeof(WebCore::DOMFormData), sizeof(WebCore::FetchHeaders), sizeof(SystemError), sizeof(JSC::JSCell), sizeof(JSC::JSString), sizeof(JSC::JSModuleLoader), sizeof(WebCore::AbortSignal), sizeof(JSC::JSPromise), sizeof(JSC::JSInternalPromise), sizeof(JSC::JSFunction), sizeof(JSC::JSGlobalObject), sizeof(JSC::JSMap), sizeof(JSC::JSValue), sizeof(JSC::Exception), sizeof(JSC::VM), sizeof(JSC::ThrowScope), sizeof(JSC::CatchScope), sizeof(FFI__ptr), sizeof(Reader__u8), sizeof(Reader__u16), sizeof(Reader__u32), sizeof(Reader__ptr), sizeof(Reader__i8), sizeof(Reader__i16), sizeof(Reader__i32), sizeof(Reader__f32), sizeof(Reader__f64), sizeof(Reader__i64), sizeof(Reader__u64), sizeof(Reader__intptr), sizeof(Crypto__getRandomValues), sizeof(Crypto__randomUUID), sizeof(Crypto__timingSafeEqual), sizeof(Zig::GlobalObject), sizeof(Bun__Path), sizeof(ArrayBufferSink), sizeof(HTTPSResponseSink), sizeof(HTTPResponseSink), sizeof(FileSink), sizeof(BrotliDecompressorSink), sizeof(BrotliCompressorSink)};
|
||||
|
||||
const char* names[41] = {"JSC__JSObject", "WebCore__DOMURL", "WebCore__DOMFormData", "WebCore__FetchHeaders", "SystemError", "JSC__JSCell", "JSC__JSString", "JSC__JSModuleLoader", "WebCore__AbortSignal", "JSC__JSPromise", "JSC__JSInternalPromise", "JSC__JSFunction", "JSC__JSGlobalObject", "JSC__JSMap", "JSC__JSValue", "JSC__Exception", "JSC__VM", "JSC__ThrowScope", "JSC__CatchScope", "FFI__ptr", "Reader__u8", "Reader__u16", "Reader__u32", "Reader__ptr", "Reader__i8", "Reader__i16", "Reader__i32", "Reader__f32", "Reader__f64", "Reader__i64", "Reader__u64", "Reader__intptr", "Crypto__getRandomValues", "Crypto__randomUUID", "Crypto__timingSafeEqual", "Zig__GlobalObject", "Bun__Path", "ArrayBufferSink", "HTTPSResponseSink", "HTTPResponseSink", "FileSink"};
|
||||
const char* names[43] = {"JSC__JSObject", "WebCore__DOMURL", "WebCore__DOMFormData", "WebCore__FetchHeaders", "SystemError", "JSC__JSCell", "JSC__JSString", "JSC__JSModuleLoader", "WebCore__AbortSignal", "JSC__JSPromise", "JSC__JSInternalPromise", "JSC__JSFunction", "JSC__JSGlobalObject", "JSC__JSMap", "JSC__JSValue", "JSC__Exception", "JSC__VM", "JSC__ThrowScope", "JSC__CatchScope", "FFI__ptr", "Reader__u8", "Reader__u16", "Reader__u32", "Reader__ptr", "Reader__i8", "Reader__i16", "Reader__i32", "Reader__f32", "Reader__f64", "Reader__i64", "Reader__u64", "Reader__intptr", "Crypto__getRandomValues", "Crypto__randomUUID", "Crypto__timingSafeEqual", "Zig__GlobalObject", "Bun__Path", "ArrayBufferSink", "HTTPSResponseSink", "HTTPResponseSink", "FileSink", "BrotliDecompressorSink", "BrotliCompressorSink"};
|
||||
|
||||
const size_t aligns[41] = {alignof(JSC::JSObject), alignof(WebCore::DOMURL), alignof(WebCore::DOMFormData), alignof(WebCore::FetchHeaders), alignof(SystemError), alignof(JSC::JSCell), alignof(JSC::JSString), alignof(JSC::JSModuleLoader), alignof(WebCore::AbortSignal), alignof(JSC::JSPromise), alignof(JSC::JSInternalPromise), alignof(JSC::JSFunction), alignof(JSC::JSGlobalObject), alignof(JSC::JSMap), alignof(JSC::JSValue), alignof(JSC::Exception), alignof(JSC::VM), alignof(JSC::ThrowScope), alignof(JSC::CatchScope), alignof(FFI__ptr), alignof(Reader__u8), alignof(Reader__u16), alignof(Reader__u32), alignof(Reader__ptr), alignof(Reader__i8), alignof(Reader__i16), alignof(Reader__i32), alignof(Reader__f32), alignof(Reader__f64), alignof(Reader__i64), alignof(Reader__u64), alignof(Reader__intptr), alignof(Crypto__getRandomValues), alignof(Crypto__randomUUID), alignof(Crypto__timingSafeEqual), alignof(Zig::GlobalObject), alignof(Bun__Path), alignof(ArrayBufferSink), alignof(HTTPSResponseSink), alignof(HTTPResponseSink), alignof(FileSink)};
|
||||
const size_t aligns[43] = {alignof(JSC::JSObject), alignof(WebCore::DOMURL), alignof(WebCore::DOMFormData), alignof(WebCore::FetchHeaders), alignof(SystemError), alignof(JSC::JSCell), alignof(JSC::JSString), alignof(JSC::JSModuleLoader), alignof(WebCore::AbortSignal), alignof(JSC::JSPromise), alignof(JSC::JSInternalPromise), alignof(JSC::JSFunction), alignof(JSC::JSGlobalObject), alignof(JSC::JSMap), alignof(JSC::JSValue), alignof(JSC::Exception), alignof(JSC::VM), alignof(JSC::ThrowScope), alignof(JSC::CatchScope), alignof(FFI__ptr), alignof(Reader__u8), alignof(Reader__u16), alignof(Reader__u32), alignof(Reader__ptr), alignof(Reader__i8), alignof(Reader__i16), alignof(Reader__i32), alignof(Reader__f32), alignof(Reader__f64), alignof(Reader__i64), alignof(Reader__u64), alignof(Reader__intptr), alignof(Crypto__getRandomValues), alignof(Crypto__randomUUID), alignof(Crypto__timingSafeEqual), alignof(Zig::GlobalObject), alignof(Bun__Path), alignof(ArrayBufferSink), alignof(HTTPSResponseSink), alignof(HTTPResponseSink), alignof(FileSink), alignof(BrotliDecompressorSink), alignof(BrotliCompressorSink)};
|
||||
|
||||
40
src/bun.js/bindings/headers.h
generated
40
src/bun.js/bindings/headers.h
generated
@@ -715,6 +715,46 @@ ZIG_DECL JSC__JSValue FileSink__start(JSC__JSGlobalObject* arg0, JSC__CallFrame*
|
||||
ZIG_DECL void FileSink__updateRef(void* arg0, bool arg1);
|
||||
ZIG_DECL JSC__JSValue FileSink__write(JSC__JSGlobalObject* arg0, JSC__CallFrame* arg1);
|
||||
|
||||
#endif
|
||||
CPP_DECL JSC__JSValue BrotliDecompressorSink__assignToStream(JSC__JSGlobalObject* arg0, JSC__JSValue JSValue1, void* arg2, void** arg3);
|
||||
CPP_DECL JSC__JSValue BrotliDecompressorSink__createObject(JSC__JSGlobalObject* arg0, void* arg1);
|
||||
CPP_DECL void BrotliDecompressorSink__detachPtr(JSC__JSValue JSValue0);
|
||||
CPP_DECL void* BrotliDecompressorSink__fromJS(JSC__JSGlobalObject* arg0, JSC__JSValue JSValue1);
|
||||
CPP_DECL void BrotliDecompressorSink__onClose(JSC__JSValue JSValue0, JSC__JSValue JSValue1);
|
||||
CPP_DECL void BrotliDecompressorSink__onReady(JSC__JSValue JSValue0, JSC__JSValue JSValue1, JSC__JSValue JSValue2);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
ZIG_DECL JSC__JSValue BrotliDecompressorSink__close(JSC__JSGlobalObject* arg0, void* arg1);
|
||||
ZIG_DECL JSC__JSValue BrotliDecompressorSink__construct(JSC__JSGlobalObject* arg0, JSC__CallFrame* arg1);
|
||||
ZIG_DECL JSC__JSValue BrotliDecompressorSink__end(JSC__JSGlobalObject* arg0, JSC__CallFrame* arg1);
|
||||
ZIG_DECL JSC__JSValue BrotliDecompressorSink__endWithSink(void* arg0, JSC__JSGlobalObject* arg1);
|
||||
ZIG_DECL void BrotliDecompressorSink__finalize(void* arg0);
|
||||
ZIG_DECL JSC__JSValue BrotliDecompressorSink__flush(JSC__JSGlobalObject* arg0, JSC__CallFrame* arg1);
|
||||
ZIG_DECL JSC__JSValue BrotliDecompressorSink__start(JSC__JSGlobalObject* arg0, JSC__CallFrame* arg1);
|
||||
ZIG_DECL void BrotliDecompressorSink__updateRef(void* arg0, bool arg1);
|
||||
ZIG_DECL JSC__JSValue BrotliDecompressorSink__write(JSC__JSGlobalObject* arg0, JSC__CallFrame* arg1);
|
||||
|
||||
#endif
|
||||
CPP_DECL JSC__JSValue BrotliCompressorSink__assignToStream(JSC__JSGlobalObject* arg0, JSC__JSValue JSValue1, void* arg2, void** arg3);
|
||||
CPP_DECL JSC__JSValue BrotliCompressorSink__createObject(JSC__JSGlobalObject* arg0, void* arg1);
|
||||
CPP_DECL void BrotliCompressorSink__detachPtr(JSC__JSValue JSValue0);
|
||||
CPP_DECL void* BrotliCompressorSink__fromJS(JSC__JSGlobalObject* arg0, JSC__JSValue JSValue1);
|
||||
CPP_DECL void BrotliCompressorSink__onClose(JSC__JSValue JSValue0, JSC__JSValue JSValue1);
|
||||
CPP_DECL void BrotliCompressorSink__onReady(JSC__JSValue JSValue0, JSC__JSValue JSValue1, JSC__JSValue JSValue2);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
ZIG_DECL JSC__JSValue BrotliCompressorSink__close(JSC__JSGlobalObject* arg0, void* arg1);
|
||||
ZIG_DECL JSC__JSValue BrotliCompressorSink__construct(JSC__JSGlobalObject* arg0, JSC__CallFrame* arg1);
|
||||
ZIG_DECL JSC__JSValue BrotliCompressorSink__end(JSC__JSGlobalObject* arg0, JSC__CallFrame* arg1);
|
||||
ZIG_DECL JSC__JSValue BrotliCompressorSink__endWithSink(void* arg0, JSC__JSGlobalObject* arg1);
|
||||
ZIG_DECL void BrotliCompressorSink__finalize(void* arg0);
|
||||
ZIG_DECL JSC__JSValue BrotliCompressorSink__flush(JSC__JSGlobalObject* arg0, JSC__CallFrame* arg1);
|
||||
ZIG_DECL JSC__JSValue BrotliCompressorSink__start(JSC__JSGlobalObject* arg0, JSC__CallFrame* arg1);
|
||||
ZIG_DECL void BrotliCompressorSink__updateRef(void* arg0, bool arg1);
|
||||
ZIG_DECL JSC__JSValue BrotliCompressorSink__write(JSC__JSGlobalObject* arg0, JSC__CallFrame* arg1);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
12
src/bun.js/bindings/headers.zig
generated
12
src/bun.js/bindings/headers.zig
generated
@@ -379,4 +379,16 @@ pub extern fn FileSink__detachPtr(JSValue0: JSC__JSValue) void;
|
||||
pub extern fn FileSink__fromJS(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue) ?*anyopaque;
|
||||
pub extern fn FileSink__onClose(JSValue0: JSC__JSValue, JSValue1: JSC__JSValue) void;
|
||||
pub extern fn FileSink__onReady(JSValue0: JSC__JSValue, JSValue1: JSC__JSValue, JSValue2: JSC__JSValue) void;
|
||||
pub extern fn BrotliDecompressorSink__assignToStream(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue, arg2: ?*anyopaque, arg3: [*c]*anyopaque) JSC__JSValue;
|
||||
pub extern fn BrotliDecompressorSink__createObject(arg0: *bindings.JSGlobalObject, arg1: ?*anyopaque) JSC__JSValue;
|
||||
pub extern fn BrotliDecompressorSink__detachPtr(JSValue0: JSC__JSValue) void;
|
||||
pub extern fn BrotliDecompressorSink__fromJS(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue) ?*anyopaque;
|
||||
pub extern fn BrotliDecompressorSink__onClose(JSValue0: JSC__JSValue, JSValue1: JSC__JSValue) void;
|
||||
pub extern fn BrotliDecompressorSink__onReady(JSValue0: JSC__JSValue, JSValue1: JSC__JSValue, JSValue2: JSC__JSValue) void;
|
||||
pub extern fn BrotliCompressorSink__assignToStream(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue, arg2: ?*anyopaque, arg3: [*c]*anyopaque) JSC__JSValue;
|
||||
pub extern fn BrotliCompressorSink__createObject(arg0: *bindings.JSGlobalObject, arg1: ?*anyopaque) JSC__JSValue;
|
||||
pub extern fn BrotliCompressorSink__detachPtr(JSValue0: JSC__JSValue) void;
|
||||
pub extern fn BrotliCompressorSink__fromJS(arg0: *bindings.JSGlobalObject, JSValue1: JSC__JSValue) ?*anyopaque;
|
||||
pub extern fn BrotliCompressorSink__onClose(JSValue0: JSC__JSValue, JSValue1: JSC__JSValue) void;
|
||||
pub extern fn BrotliCompressorSink__onReady(JSValue0: JSC__JSValue, JSValue1: JSC__JSValue, JSValue2: JSC__JSValue) void;
|
||||
pub extern fn ZigException__fromException(arg0: [*c]bindings.Exception) ZigException;
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
import { resolve } from "path";
|
||||
|
||||
const classes = ["ArrayBufferSink", "FileSink", "HTTPResponseSink", "HTTPSResponseSink"];
|
||||
const SINK_COUNT = 5;
|
||||
const classes = [
|
||||
"ArrayBufferSink",
|
||||
"FileSink",
|
||||
"HTTPResponseSink",
|
||||
"HTTPSResponseSink",
|
||||
"BrotliDecompressorSink",
|
||||
"BrotliCompressorSink",
|
||||
];
|
||||
|
||||
function names(name) {
|
||||
return {
|
||||
|
||||
@@ -518,6 +518,20 @@ pub const DrainResult = union(enum) {
|
||||
aborted: void,
|
||||
};
|
||||
|
||||
pub const ErrorMessage = struct {
|
||||
message: bun.String = bun.String.empty,
|
||||
code: bun.String = bun.String.empty,
|
||||
|
||||
pub fn toJS(this: *const @This(), globalObject: *JSC.JSGlobalObject) JSValue {
|
||||
defer this.message.deref();
|
||||
defer this.code.deref();
|
||||
return (JSC.SystemError{
|
||||
.message = this.message,
|
||||
.code = this.code,
|
||||
}).toErrorInstance(globalObject);
|
||||
}
|
||||
};
|
||||
|
||||
pub const StreamResult = union(Tag) {
|
||||
owned: bun.ByteList,
|
||||
owned_and_done: bun.ByteList,
|
||||
@@ -528,6 +542,7 @@ pub const StreamResult = union(Tag) {
|
||||
pending: *Pending,
|
||||
err: Syscall.Error,
|
||||
done: void,
|
||||
error_message: ErrorMessage,
|
||||
|
||||
pub const Tag = enum {
|
||||
owned,
|
||||
@@ -539,6 +554,7 @@ pub const StreamResult = union(Tag) {
|
||||
pending,
|
||||
err,
|
||||
done,
|
||||
error_message,
|
||||
};
|
||||
|
||||
pub fn slice(this: *const StreamResult) []const u8 {
|
||||
@@ -555,6 +571,7 @@ pub const StreamResult = union(Tag) {
|
||||
pending: *Writable.Pending,
|
||||
|
||||
err: Syscall.Error,
|
||||
error_message: ErrorMessage,
|
||||
done: void,
|
||||
|
||||
owned: Blob.SizeType,
|
||||
@@ -664,6 +681,11 @@ pub const StreamResult = union(Tag) {
|
||||
promise_value.protect();
|
||||
break :brk promise_value;
|
||||
},
|
||||
|
||||
.error_message => brk: {
|
||||
globalThis.throwValue(this.error_message.toJS(globalThis));
|
||||
break :brk JSC.JSValue.jsUndefined();
|
||||
},
|
||||
};
|
||||
}
|
||||
};
|
||||
@@ -806,6 +828,9 @@ pub const StreamResult = union(Tag) {
|
||||
.err => |err| {
|
||||
return JSC.JSPromise.rejectedPromise(globalThis, JSValue.c(err.toJS(globalThis))).asValue(globalThis);
|
||||
},
|
||||
.error_message => {
|
||||
return JSC.JSPromise.rejectedPromise(globalThis, this.error_message.toJS(globalThis)).asValue(globalThis);
|
||||
},
|
||||
|
||||
// false == controller.close()
|
||||
// undefined == noop, but we probably won't send it
|
||||
@@ -1896,6 +1921,382 @@ pub const ArrayBufferSink = struct {
|
||||
pub const JSSink = NewJSSink(@This(), "ArrayBufferSink");
|
||||
};
|
||||
|
||||
pub const BrotliCompressorSink = struct {
|
||||
state: ?*bun.brotli.BrotliEncoderState = null,
|
||||
allocator: std.mem.Allocator,
|
||||
done: bool = false,
|
||||
signal: Signal = .{},
|
||||
next: ?Sink = null,
|
||||
output_buffer: bun.ByteList = bun.ByteList{},
|
||||
chunk_size: u32 = 16 * 1024,
|
||||
total_size: usize = 0,
|
||||
|
||||
pub fn connect(this: *BrotliCompressorSink, signal: Signal) void {
|
||||
std.debug.assert(this.reader == null);
|
||||
this.signal = signal;
|
||||
}
|
||||
|
||||
pub fn start(this: *BrotliCompressorSink, _: StreamStart) JSC.Node.Maybe(void) {
|
||||
this.output_buffer.len = 0;
|
||||
|
||||
if (this.state == null) {
|
||||
this.state = bun.brotli.BrotliEncoderState.init();
|
||||
}
|
||||
|
||||
// switch (stream_start) {
|
||||
// .BrotliCompressorSink => |config| {
|
||||
// if (config.chunk_size > 0) {
|
||||
// list.ensureTotalCapacityPrecise(config.chunk_size) catch return .{ .err = Syscall.Error.oom };
|
||||
// this.bytes.update(list);
|
||||
// }
|
||||
|
||||
// this.as_uint8array = config.as_uint8array;
|
||||
// this.streaming = config.stream;
|
||||
// },
|
||||
// else => {},
|
||||
// }
|
||||
|
||||
this.done = false;
|
||||
|
||||
this.signal.start();
|
||||
return .{ .result = {} };
|
||||
}
|
||||
|
||||
pub fn flush(this: *BrotliCompressorSink) JSC.Node.Maybe(void) {
|
||||
_ = this;
|
||||
return .{ .result = {} };
|
||||
}
|
||||
|
||||
pub fn flushFromJS(this: *BrotliCompressorSink, globalThis: *JSGlobalObject, wait: bool) JSC.Node.Maybe(JSValue) {
|
||||
_ = globalThis;
|
||||
_ = wait;
|
||||
|
||||
if (this.state) |state| {
|
||||
var output_slice = this.output_buffer.ptr[0..this.output_buffer.cap];
|
||||
std.debug.assert(state.flush(&output_slice, &output_slice, &this.total_size));
|
||||
}
|
||||
|
||||
return .{ .result = JSC.JSValue.jsNumber(0) };
|
||||
}
|
||||
|
||||
pub fn finalize(this: *BrotliCompressorSink) void {
|
||||
if (this.state) |state| {
|
||||
state.deinit();
|
||||
}
|
||||
this.output_buffer.deinitWithAllocator(bun.default_allocator);
|
||||
this.allocator.destroy(this);
|
||||
}
|
||||
|
||||
pub fn init(allocator: std.mem.Allocator, next: ?Sink) !*BrotliCompressorSink {
|
||||
var this = try allocator.create(BrotliCompressorSink);
|
||||
this.* = BrotliCompressorSink{
|
||||
.bytes = bun.ByteList.init(&.{}),
|
||||
.allocator = allocator,
|
||||
.next = next,
|
||||
};
|
||||
return this;
|
||||
}
|
||||
|
||||
pub fn construct(
|
||||
this: *BrotliCompressorSink,
|
||||
allocator: std.mem.Allocator,
|
||||
) void {
|
||||
this.* = BrotliCompressorSink{
|
||||
.allocator = allocator,
|
||||
.next = null,
|
||||
.state = null,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn write(this: *@This(), data: StreamResult) StreamResult.Writable {
|
||||
var state = this.state orelse return .{ .done = {} };
|
||||
var initial_slice = data.slice();
|
||||
var slice = initial_slice;
|
||||
while (slice.len > 0) {
|
||||
this.output_buffer.ensureUnusedCapacity(
|
||||
bun.default_allocator,
|
||||
bun.brotli.BrotliEncoderMaxCompressedSize(slice.len),
|
||||
) catch {
|
||||
return .{ .err = Syscall.Error.oom };
|
||||
};
|
||||
|
||||
var output_slice = this.output_buffer.ptr[0..this.output_buffer.cap];
|
||||
std.debug.assert(state.write(&slice, &output_slice, &this.total_size));
|
||||
slice = initial_slice;
|
||||
std.debug.assert(state.flush(&slice, &output_slice, &this.total_size));
|
||||
|
||||
this.output_buffer.len = @as(u32, @truncate(this.total_size));
|
||||
}
|
||||
|
||||
return .{ .owned = @as(Blob.SizeType, @truncate(initial_slice.len - slice.len)) };
|
||||
}
|
||||
pub const writeBytes = write;
|
||||
pub fn writeLatin1(this: *@This(), data: StreamResult) StreamResult.Writable {
|
||||
if (strings.isAllASCII(data.slice())) {
|
||||
return this.write(data);
|
||||
}
|
||||
|
||||
var allocated = strings.allocateLatin1IntoUTF8(bun.default_allocator, []const u8, data.slice()) catch {
|
||||
return .{ .err = Syscall.Error.oom };
|
||||
};
|
||||
defer bun.default_allocator.free(allocated);
|
||||
return this.write(.{ .temporary = bun.ByteList.init(allocated) });
|
||||
}
|
||||
pub fn writeUTF16(this: *@This(), data: StreamResult) StreamResult.Writable {
|
||||
if (this.next) |*next| {
|
||||
return next.writeUTF16(data);
|
||||
}
|
||||
var bytes = strings.toUTF8Alloc(bun.default_allocator, @alignCast(std.mem.bytesAsSlice(u16, data.slice()))) catch {
|
||||
return .{ .err = Syscall.Error.oom };
|
||||
};
|
||||
defer bun.default_allocator.free(bytes);
|
||||
return this.write(.{ .temporary = bun.ByteList.init(bytes) });
|
||||
}
|
||||
|
||||
pub fn end(this: *BrotliCompressorSink, err: ?Syscall.Error) JSC.Node.Maybe(void) {
|
||||
if (this.next) |*next| {
|
||||
return next.end(err);
|
||||
}
|
||||
this.signal.close(err);
|
||||
return .{ .result = {} };
|
||||
}
|
||||
|
||||
pub fn toJS(this: *BrotliCompressorSink, globalThis: *JSGlobalObject) JSValue {
|
||||
return JSSink.createObject(globalThis, this);
|
||||
}
|
||||
|
||||
pub fn endFromJS(this: *@This(), globalThis: *JSGlobalObject) JSC.Node.Maybe(JSValue) {
|
||||
var state = this.state orelse return .{ .result = JSC.JSValue.jsUndefined() };
|
||||
var finishing_byte_slice = this.output_buffer.ptr[0..this.output_buffer.cap];
|
||||
var finish2 = finishing_byte_slice;
|
||||
finish2 = finishing_byte_slice;
|
||||
_ = state.finish(null, &finishing_byte_slice, &this.total_size);
|
||||
var bytes = this.output_buffer.ptr[0..this.total_size];
|
||||
state.deinit();
|
||||
this.state = null;
|
||||
|
||||
this.output_buffer = .{};
|
||||
std.debug.assert(this.next == null);
|
||||
this.done = true;
|
||||
this.signal.close(null);
|
||||
return .{ .result = JSC.ArrayBuffer.fromBytes(bytes, .ArrayBuffer).toJS(globalThis, null) };
|
||||
}
|
||||
|
||||
pub fn sink(this: *BrotliCompressorSink) Sink {
|
||||
return Sink.init(this);
|
||||
}
|
||||
|
||||
pub const JSSink = NewJSSink(@This(), "BrotliCompressorSink");
|
||||
};
|
||||
|
||||
pub const BrotliDecompressorSink = struct {
|
||||
state: ?*bun.brotli.BrotliDecoderState = null,
|
||||
allocator: std.mem.Allocator,
|
||||
done: bool = false,
|
||||
signal: Signal = .{},
|
||||
streaming: bool = false,
|
||||
next: ?Sink = null,
|
||||
output_buffer: bun.ByteList = bun.ByteList{},
|
||||
chunk_size: u32 = 16 * 1024,
|
||||
total_size: usize = 0,
|
||||
|
||||
pub fn connect(this: *BrotliDecompressorSink, signal: Signal) void {
|
||||
std.debug.assert(this.reader == null);
|
||||
this.signal = signal;
|
||||
}
|
||||
|
||||
pub fn start(this: *BrotliDecompressorSink, _: StreamStart) JSC.Node.Maybe(void) {
|
||||
this.output_buffer.len = 0;
|
||||
|
||||
if (this.state) |existing| {
|
||||
if (existing.isUsed()) {
|
||||
existing.deinit();
|
||||
this.state = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.state == null) {
|
||||
this.state = bun.brotli.BrotliDecoderState.init();
|
||||
}
|
||||
|
||||
// switch (stream_start) {
|
||||
// .BrotliDecompressorSink => |config| {
|
||||
// if (config.chunk_size > 0) {
|
||||
// list.ensureTotalCapacityPrecise(config.chunk_size) catch return .{ .err = Syscall.Error.oom };
|
||||
// this.bytes.update(list);
|
||||
// }
|
||||
|
||||
// this.as_uint8array = config.as_uint8array;
|
||||
// this.streaming = config.stream;
|
||||
// },
|
||||
// else => {},
|
||||
// }
|
||||
|
||||
this.done = false;
|
||||
|
||||
this.signal.start();
|
||||
return .{ .result = {} };
|
||||
}
|
||||
|
||||
pub fn flush(this: *BrotliDecompressorSink) JSC.Node.Maybe(void) {
|
||||
_ = this;
|
||||
return .{ .result = {} };
|
||||
}
|
||||
|
||||
pub fn flushFromJS(this: *BrotliDecompressorSink, globalThis: *JSGlobalObject, wait: bool) JSC.Node.Maybe(JSValue) {
|
||||
_ = wait;
|
||||
|
||||
if (this.output_buffer.len > 0) {
|
||||
if (this.next) |*next| {
|
||||
var list = this.output_buffer;
|
||||
this.output_buffer = bun.ByteList.init("");
|
||||
return .{ .result = next.writeBytes(.{ .owned = list }).toJS(globalThis) };
|
||||
}
|
||||
|
||||
return .{ .result = JSC.JSValue.jsNumber(this.output_buffer.len) };
|
||||
}
|
||||
|
||||
return .{ .result = JSC.JSValue.jsNumber(0) };
|
||||
}
|
||||
|
||||
pub fn finalize(this: *BrotliDecompressorSink) void {
|
||||
if (this.state) |state| {
|
||||
state.deinit();
|
||||
}
|
||||
this.output_buffer.deinitWithAllocator(bun.default_allocator);
|
||||
this.allocator.destroy(this);
|
||||
}
|
||||
|
||||
pub fn init(allocator: std.mem.Allocator, next: ?Sink) !*BrotliDecompressorSink {
|
||||
var this = try allocator.create(BrotliDecompressorSink);
|
||||
this.* = BrotliDecompressorSink{
|
||||
.bytes = bun.ByteList.init(&.{}),
|
||||
.allocator = allocator,
|
||||
.next = next,
|
||||
};
|
||||
return this;
|
||||
}
|
||||
|
||||
pub fn construct(
|
||||
this: *BrotliDecompressorSink,
|
||||
allocator: std.mem.Allocator,
|
||||
) void {
|
||||
this.* = BrotliDecompressorSink{
|
||||
.allocator = allocator,
|
||||
.next = null,
|
||||
.state = null,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn write(this: *@This(), data: StreamResult) StreamResult.Writable {
|
||||
var state = this.state orelse return .{ .done = {} };
|
||||
var initial_slice = data.slice();
|
||||
var slice = initial_slice;
|
||||
|
||||
while (true) {
|
||||
if (this.output_buffer.cap - this.output_buffer.len < this.chunk_size) {
|
||||
this.output_buffer.ensureUnusedCapacity(bun.default_allocator, this.chunk_size) catch {
|
||||
return .{ .err = Syscall.Error.oom };
|
||||
};
|
||||
}
|
||||
var output_slice = this.output_buffer.ptr[this.output_buffer.len..this.output_buffer.cap];
|
||||
const res = state.write(&slice, &output_slice, &this.total_size);
|
||||
this.output_buffer.len += @as(u32, @truncate(this.total_size));
|
||||
|
||||
switch (res) {
|
||||
.success => {
|
||||
if (this.next) |*next| {
|
||||
var output_buffer = this.output_buffer;
|
||||
this.output_buffer = .{};
|
||||
return next.writeBytes(.{ .owned_and_done = output_buffer });
|
||||
}
|
||||
this.signal.ready(null, null);
|
||||
return .{ .owned_and_done = @as(Blob.SizeType, @truncate(initial_slice.len - slice.len)) };
|
||||
},
|
||||
.@"error" => {
|
||||
const code = state.getErrorCode();
|
||||
return .{
|
||||
.error_message = .{
|
||||
.code = bun.String.static(code.code()),
|
||||
.message = bun.String.static(code.message()),
|
||||
},
|
||||
};
|
||||
},
|
||||
.needs_more_input => {
|
||||
this.signal.ready(null, null);
|
||||
return .{ .owned = @as(Blob.SizeType, @truncate(initial_slice.len - slice.len)) };
|
||||
},
|
||||
|
||||
.needs_more_output => {
|
||||
if (this.next) |*next| {
|
||||
var output_buffer = this.output_buffer;
|
||||
this.output_buffer = .{};
|
||||
return next.writeBytes(.{ .owned = output_buffer });
|
||||
}
|
||||
|
||||
this.output_buffer.ensureUnusedCapacity(bun.default_allocator, this.chunk_size) catch {
|
||||
return .{ .err = Syscall.Error.oom };
|
||||
};
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
pub const writeBytes = write;
|
||||
pub fn writeLatin1(this: *@This(), data: StreamResult) StreamResult.Writable {
|
||||
if (strings.isAllASCII(data.slice())) {
|
||||
return this.write(data);
|
||||
}
|
||||
|
||||
var allocated = strings.allocateLatin1IntoUTF8(bun.default_allocator, []const u8, data.slice()) catch {
|
||||
return .{ .err = Syscall.Error.oom };
|
||||
};
|
||||
defer bun.default_allocator.free(allocated);
|
||||
return this.write(.{ .temporary = bun.ByteList.init(allocated) });
|
||||
}
|
||||
pub fn writeUTF16(this: *@This(), data: StreamResult) StreamResult.Writable {
|
||||
if (this.next) |*next| {
|
||||
return next.writeUTF16(data);
|
||||
}
|
||||
var bytes = strings.toUTF8Alloc(bun.default_allocator, @alignCast(std.mem.bytesAsSlice(u16, data.slice()))) catch {
|
||||
return .{ .err = Syscall.Error.oom };
|
||||
};
|
||||
defer bun.default_allocator.free(bytes);
|
||||
return this.write(.{ .temporary = bun.ByteList.init(bytes) });
|
||||
}
|
||||
|
||||
pub fn end(this: *BrotliDecompressorSink, err: ?Syscall.Error) JSC.Node.Maybe(void) {
|
||||
if (this.next) |*next| {
|
||||
return next.end(err);
|
||||
}
|
||||
this.signal.close(err);
|
||||
return .{ .result = {} };
|
||||
}
|
||||
|
||||
pub fn toJS(this: *BrotliDecompressorSink, globalThis: *JSGlobalObject) JSValue {
|
||||
return JSSink.createObject(globalThis, this);
|
||||
}
|
||||
|
||||
pub fn endFromJS(this: *@This(), globalThis: *JSGlobalObject) JSC.Node.Maybe(JSValue) {
|
||||
if (this.state) |state| {
|
||||
state.deinit();
|
||||
this.state = null;
|
||||
}
|
||||
|
||||
std.debug.assert(this.next == null);
|
||||
var list = this.output_buffer.listManaged(this.allocator);
|
||||
this.output_buffer = bun.ByteList.init("");
|
||||
this.done = true;
|
||||
this.signal.close(null);
|
||||
return .{ .result = JSC.JSValue.createBuffer(globalThis, list.items, bun.default_allocator) };
|
||||
}
|
||||
|
||||
pub fn sink(this: *BrotliDecompressorSink) Sink {
|
||||
return Sink.init(this);
|
||||
}
|
||||
|
||||
pub const JSSink = NewJSSink(@This(), "BrotliDecompressorSink");
|
||||
};
|
||||
|
||||
pub fn NewJSSink(comptime SinkType: type, comptime name_: []const u8) type {
|
||||
return struct {
|
||||
sink: SinkType,
|
||||
|
||||
@@ -1539,3 +1539,5 @@ pub const WTF = struct {
|
||||
pub const ArenaAllocator = @import("./ArenaAllocator.zig").ArenaAllocator;
|
||||
|
||||
pub const Wyhash = @import("./wyhash.zig").Wyhash;
|
||||
|
||||
pub const brotli = @import("./deps/brotli.zig");
|
||||
|
||||
205
src/compress.zig
Normal file
205
src/compress.zig
Normal file
@@ -0,0 +1,205 @@
|
||||
const bun = @import("root").bun;
|
||||
const std = @import("std");
|
||||
const zlib = @import("./zlib.zig");
|
||||
const brotli = bun.brotli;
|
||||
|
||||
const String = bun.String;
|
||||
|
||||
pub const Error = struct {
|
||||
// To workaround a zig compiler bug, we avoid using String here.
|
||||
code: []const u8,
|
||||
message: []const u8,
|
||||
};
|
||||
|
||||
pub const Ownership = enum { transfer, must_copy };
|
||||
pub const Completion = enum { last, not_last };
|
||||
|
||||
pub const Controller = struct {
|
||||
ctx: *anyopaque,
|
||||
max_to_receive: ?*usize = null,
|
||||
closed: *bool,
|
||||
receive_data_fn: *const fn (*anyopaque, []const u8, Ownership, Completion) void,
|
||||
receive_error_fn: *const fn (*anyopaque, Error) void,
|
||||
pull_fn: *const fn (*anyopaque) void,
|
||||
|
||||
pub fn enqueue(this: *const Controller, data: []const u8, ownership: Ownership, completion: Completion) void {
|
||||
this.receive_data_fn(this.ctx, data, ownership, completion);
|
||||
}
|
||||
|
||||
pub fn fail(this: *const Controller, err: Error) void {
|
||||
this.receive_error_fn(this.ctx, err);
|
||||
}
|
||||
|
||||
pub fn pull(this: *const Controller) void {
|
||||
this.pull_fn(this.ctx);
|
||||
}
|
||||
|
||||
pub fn init(comptime ContextType: type, context: ContextType) Controller {
|
||||
const Context = std.meta.Child(ContextType);
|
||||
return Controller{
|
||||
.ctx = @as(*anyopaque, @ptrCast(context)),
|
||||
.closed = @as(*bool, @ptrCast(&context.closed)),
|
||||
.receive_data_fn = @as(*const fn (*anyopaque, []const u8, Ownership, Completion) void, @ptrCast(&Context.onData)),
|
||||
.receive_error_fn = @as(*const fn (*anyopaque, Error) void, @ptrCast(&Context.onError)),
|
||||
.pull_fn = @as(*const fn (*anyopaque) void, @ptrCast(&Context.onPull)),
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
pub const Compressor = union(enum) {
|
||||
BrotliEncoder: Brotli.Encoder,
|
||||
BrotliDecoder: Brotli.Decoder,
|
||||
|
||||
pub fn write(this: *Compressor, data: []const u8, controller: Controller) void {
|
||||
switch (this.*) {
|
||||
.BrotliEncoder => {
|
||||
this.BrotliEncoder.write(data, controller);
|
||||
},
|
||||
.BrotliDecoder => {
|
||||
this.BrotliDecoder.write(data, controller);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn end(this: *Compressor, controller: Controller) void {
|
||||
switch (this.*) {
|
||||
.BrotliEncoder => {
|
||||
this.BrotliEncoder.end(controller);
|
||||
},
|
||||
.BrotliDecoder => {
|
||||
this.BrotliDecoder.end(controller);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn initWithType(comptime Type: type, value: Type) !*Compressor {
|
||||
var compressor = try bun.default_allocator.create(Compressor);
|
||||
compressor.* = switch (comptime Type) {
|
||||
Brotli.Encoder => .{ .BrotliEncoder = value },
|
||||
Brotli.Decoder => .{ .BrotliDecoder = value },
|
||||
else => @compileError("unsupported compressor type"),
|
||||
};
|
||||
return compressor;
|
||||
}
|
||||
|
||||
pub fn init(compressor: anytype) !*Compressor {
|
||||
return initWithType(@TypeOf(compressor), compressor);
|
||||
}
|
||||
};
|
||||
|
||||
pub const Brotli = struct {
|
||||
pub const Encoder = struct {
|
||||
state: ?*brotli.BrotliEncoderState,
|
||||
|
||||
pub fn initWithoutOptions() Encoder {
|
||||
return Encoder{
|
||||
.state = brotli.BrotliEncoderState.init(),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn write(this: *Encoder, data: []const u8, controller: Controller) void {
|
||||
var state = this.state orelse return;
|
||||
var input = data;
|
||||
|
||||
consume(state, controller);
|
||||
std.debug.assert(state.write(&input, null, null));
|
||||
std.debug.assert(state.flush(null, null, null));
|
||||
consume(state, controller);
|
||||
}
|
||||
|
||||
fn consume(state: *brotli.BrotliEncoderState, controller: Controller) void {
|
||||
while (!controller.closed.*) {
|
||||
const to_receive = if (controller.max_to_receive) |max| max.* else 0;
|
||||
if (isFull(to_receive)) break;
|
||||
const taken = state.take(to_receive);
|
||||
if (taken.len == 0)
|
||||
break;
|
||||
|
||||
controller.enqueue(
|
||||
taken,
|
||||
.must_copy,
|
||||
.not_last,
|
||||
);
|
||||
|
||||
if (!state.hasMoreOutput())
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn end(this: *Encoder, controller: Controller) void {
|
||||
var state = this.state orelse return;
|
||||
this.state = null;
|
||||
std.debug.assert(state.finish(null, null, null));
|
||||
consume(state, controller);
|
||||
state.deinit();
|
||||
}
|
||||
};
|
||||
|
||||
pub const Decoder = struct {
|
||||
state: ?*brotli.BrotliDecoderState,
|
||||
|
||||
pub fn initWithoutOptions() Decoder {
|
||||
return Decoder{
|
||||
.state = brotli.BrotliDecoderState.init(),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn write(this: *Decoder, data: []const u8, controller: Controller) void {
|
||||
var state = this.state orelse return;
|
||||
var input = data;
|
||||
while (!controller.closed.* and !state.isFinished()) {
|
||||
switch (state.write(&input, null, null)) {
|
||||
.success => {
|
||||
consume(state, controller, true);
|
||||
return;
|
||||
},
|
||||
.@"error" => {
|
||||
const code = state.getErrorCode();
|
||||
controller.fail(Error{
|
||||
.code = code.code(),
|
||||
.message = code.message(),
|
||||
});
|
||||
return;
|
||||
},
|
||||
.needs_more_input => {
|
||||
controller.pull();
|
||||
return;
|
||||
},
|
||||
.needs_more_output => {
|
||||
consume(state, controller, false);
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn consume(state: *brotli.BrotliDecoderState, controller: Controller, is_last: bool) void {
|
||||
while (!controller.closed.*) {
|
||||
const to_receive = if (controller.max_to_receive) |max| max.* else 0;
|
||||
if (isFull(to_receive)) break;
|
||||
const taken = state.take(to_receive);
|
||||
if (taken.len == 0)
|
||||
break;
|
||||
|
||||
controller.enqueue(
|
||||
taken,
|
||||
.must_copy,
|
||||
if (!state.hasMoreOutput() and is_last) .last else .not_last,
|
||||
);
|
||||
|
||||
if (!state.hasMoreOutput())
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn end(this: *Decoder, controller: Controller) void {
|
||||
var state = this.state orelse return;
|
||||
this.state = null;
|
||||
consume(state, controller, true);
|
||||
state.deinit();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
fn isFull(size: usize) bool {
|
||||
return size == std.math.maxInt(usize);
|
||||
}
|
||||
1
src/deps/brotli
Submodule
1
src/deps/brotli
Submodule
Submodule src/deps/brotli added at dd3eb162b0
423
src/deps/brotli.zig
Normal file
423
src/deps/brotli.zig
Normal file
@@ -0,0 +1,423 @@
|
||||
const bun = @import("root").bun;
|
||||
pub const brotli_alloc_func = ?*const fn (?*anyopaque, usize) callconv(.C) ?*anyopaque;
|
||||
pub const brotli_free_func = ?*const fn (?*anyopaque, ?*anyopaque) callconv(.C) void;
|
||||
pub const struct_BrotliSharedDictionaryStruct = opaque {};
|
||||
pub const BrotliSharedDictionary = struct_BrotliSharedDictionaryStruct;
|
||||
pub const BROTLI_SHARED_DICTIONARY_RAW: c_int = 0;
|
||||
pub const BROTLI_SHARED_DICTIONARY_SERIALIZED: c_int = 1;
|
||||
pub const enum_BrotliSharedDictionaryType = c_uint;
|
||||
pub const BrotliSharedDictionaryType = enum_BrotliSharedDictionaryType;
|
||||
pub extern fn BrotliSharedDictionaryCreateInstance(alloc_func: brotli_alloc_func, free_func: brotli_free_func, ctx: ?*anyopaque) ?*BrotliSharedDictionary;
|
||||
pub extern fn BrotliSharedDictionaryDestroyInstance(dict: ?*BrotliSharedDictionary) void;
|
||||
pub extern fn BrotliSharedDictionaryAttach(dict: ?*BrotliSharedDictionary, @"type": BrotliSharedDictionaryType, data_size: usize, data: [*c]const u8) c_int;
|
||||
|
||||
fn default_brotli_alloc_fn(ctx: ?*anyopaque, size: usize) callconv(.C) ?*anyopaque {
|
||||
_ = ctx;
|
||||
return bun.Mimalloc.mi_malloc(size);
|
||||
}
|
||||
|
||||
fn default_brotli_free_fn(ctx: ?*anyopaque, ptr: ?*anyopaque) callconv(.C) void {
|
||||
_ = ctx;
|
||||
bun.Mimalloc.mi_free(ptr);
|
||||
}
|
||||
|
||||
pub const BrotliDecoderState = opaque {
|
||||
pub fn init() *BrotliDecoderState {
|
||||
return BrotliDecoderCreateInstance(default_brotli_alloc_fn, default_brotli_free_fn, null);
|
||||
}
|
||||
|
||||
pub fn deinit(self: *BrotliDecoderState) void {
|
||||
BrotliDecoderDestroyInstance(self);
|
||||
}
|
||||
|
||||
pub fn isFinished(self: *const BrotliDecoderState) bool {
|
||||
return BrotliDecoderIsFinished(self) == BROTLI_TRUE;
|
||||
}
|
||||
|
||||
pub fn isUsed(self: *const BrotliDecoderState) bool {
|
||||
return BrotliDecoderIsUsed(self) == BROTLI_TRUE;
|
||||
}
|
||||
|
||||
pub fn setParameter(self: *BrotliDecoderState, param: BrotliDecoderParameter, value: u32) bool {
|
||||
return BrotliDecoderSetParameter(self, param, value) == BROTLI_TRUE;
|
||||
}
|
||||
|
||||
pub fn write(self: *BrotliDecoderState, input: ?*[]const u8, output: ?*[]u8, total_size: ?*usize) BrotliDecoderResult {
|
||||
var input_len: usize = 0;
|
||||
var input_ptr: ?[*]const u8 = null;
|
||||
|
||||
var output_len: usize = 0;
|
||||
var output_ptr: ?[*]u8 = null;
|
||||
|
||||
if (input) |in| {
|
||||
input_len = in.len;
|
||||
input_ptr = in.ptr;
|
||||
}
|
||||
|
||||
if (output) |out| {
|
||||
output_len = out.len;
|
||||
output_ptr = out.ptr;
|
||||
}
|
||||
|
||||
defer {
|
||||
if (input) |in| {
|
||||
in.len = input_len;
|
||||
if (input_ptr != null)
|
||||
in.ptr = input_ptr.?;
|
||||
}
|
||||
|
||||
if (output) |out| {
|
||||
out.len = output_len;
|
||||
if (output_ptr != null)
|
||||
out.ptr = output_ptr.?;
|
||||
}
|
||||
}
|
||||
return BrotliDecoderDecompressStream(self, &input_len, &input_ptr, &output_len, &output_ptr, total_size);
|
||||
}
|
||||
|
||||
pub fn getErrorCode(self: *const BrotliDecoderState) BrotliDecoderErrorCode {
|
||||
return BrotliDecoderGetErrorCode(self);
|
||||
}
|
||||
|
||||
pub fn hasMoreOutput(self: *const BrotliDecoderState) bool {
|
||||
return BrotliDecoderHasMoreOutput(self) == BROTLI_TRUE;
|
||||
}
|
||||
|
||||
pub fn take(self: *BrotliDecoderState, requested: usize) []const u8 {
|
||||
var size: usize = requested;
|
||||
var ptr = BrotliDecoderTakeOutput(self, &size) orelse return "";
|
||||
return ptr[0..size];
|
||||
}
|
||||
};
|
||||
|
||||
pub const BrotliEncoderState = opaque {
|
||||
pub fn init() *BrotliEncoderState {
|
||||
return BrotliEncoderCreateInstance(default_brotli_alloc_fn, default_brotli_free_fn, null);
|
||||
}
|
||||
|
||||
pub fn deinit(self: *BrotliEncoderState) void {
|
||||
BrotliEncoderDestroyInstance(self);
|
||||
}
|
||||
|
||||
pub fn setParameter(self: *BrotliEncoderState, param: BrotliEncoderParameter, value: u32) bool {
|
||||
return BrotliEncoderSetParameter(self, param, value) == BROTLI_TRUE;
|
||||
}
|
||||
|
||||
pub fn isFinished(self: *BrotliEncoderState) bool {
|
||||
return BrotliEncoderIsFinished(self) == BROTLI_TRUE;
|
||||
}
|
||||
|
||||
pub fn hasMoreOutput(self: *BrotliEncoderState) bool {
|
||||
return BrotliEncoderHasMoreOutput(self) == BROTLI_TRUE;
|
||||
}
|
||||
|
||||
pub fn take(self: *BrotliEncoderState, size: usize) []const u8 {
|
||||
var output_len = size;
|
||||
var ptr = BrotliEncoderTakeOutput(self, &output_len) orelse return "";
|
||||
return ptr[0..output_len];
|
||||
}
|
||||
|
||||
/// Compresses input stream to output stream.
|
||||
///
|
||||
/// The values *available_in and *available_out must specify the number of
|
||||
/// bytes addressable at *next_in and *next_out respectively. When
|
||||
/// *available_out is 0, next_out is allowed to be NULL.
|
||||
///
|
||||
/// After each call, *available_in will be decremented by the amount of
|
||||
/// input bytes consumed, and the *next_in pointer will be incremented by that
|
||||
/// amount. Similarly, *available_out will be decremented by the amount of
|
||||
/// output bytes written, and the *next_out pointer will be incremented by
|
||||
/// that amount.
|
||||
///
|
||||
/// total_out, if it is not a null-pointer, will be set to the number of
|
||||
/// bytes decompressed since the last state initialization.
|
||||
///
|
||||
/// Internally workflow consists of 3 tasks:
|
||||
///
|
||||
/// (optionally) copy input data to internal buffer / actually compress data
|
||||
/// and (optionally) store it to internal buffer / (optionally) copy
|
||||
/// compressed bytes from internal buffer to output stream / Whenever all 3
|
||||
/// tasks can't move forward anymore, or error occurs, this method returns the
|
||||
/// control flow to caller.
|
||||
///
|
||||
/// op is used to perform flush, finish the stream, or inject metadata
|
||||
/// block. See BrotliEncoderOperation for more information.
|
||||
///
|
||||
/// Flushing the stream means forcing encoding of all input passed to /
|
||||
/// encoder and completing the current output block, so it could be fully /
|
||||
/// decoded by stream decoder. To perform flush set op to /
|
||||
/// BROTLI_OPERATION_FLUSH. Under some circumstances (e.g. lack of output /
|
||||
/// stream capacity) this operation would require several calls to /
|
||||
/// BrotliEncoderCompressStream. The method must be called again until both /
|
||||
/// input stream is depleted and encoder has no more output (see /
|
||||
/// BrotliEncoderHasMoreOutput) after the method is called.
|
||||
///
|
||||
/// Finishing the stream means encoding of all input passed to encoder and /
|
||||
/// adding specific "final" marks, so stream decoder could determine that /
|
||||
/// stream is complete. To perform finish set op to BROTLI_OPERATION_FINISH. /
|
||||
/// Under some circumstances (e.g. lack of output stream capacity) this /
|
||||
/// operation would require several calls to BrotliEncoderCompressStream. The
|
||||
/// method must be called again until both input stream is depleted and /
|
||||
/// encoder has no more output (see BrotliEncoderHasMoreOutput) after the /
|
||||
/// method is called.
|
||||
///
|
||||
/// Warning
|
||||
/// When flushing and finishing, op should not change until operation is complete; input stream should not be swapped, reduced or extended as well.
|
||||
pub fn compress(self: *BrotliEncoderState, op: BrotliEncoderOperation, input: ?*[]const u8, output: ?*[]u8, encoded_size: ?*usize) bool {
|
||||
var input_ptr: ?[*]const u8 = null;
|
||||
var input_len: usize = 0;
|
||||
var output_ptr: ?[*]u8 = null;
|
||||
var output_len: usize = 0;
|
||||
if (input) |in| {
|
||||
input_ptr = in.ptr;
|
||||
input_len = in.len;
|
||||
}
|
||||
|
||||
if (output) |out| {
|
||||
output_ptr = out.ptr;
|
||||
output_len = out.len;
|
||||
}
|
||||
defer {
|
||||
if (output) |out| {
|
||||
if (output_ptr) |a|
|
||||
out.ptr = a;
|
||||
out.len = output_len;
|
||||
}
|
||||
|
||||
if (input) |in| {
|
||||
if (input_ptr) |a|
|
||||
in.ptr = a;
|
||||
in.len = input_len;
|
||||
}
|
||||
}
|
||||
return BrotliEncoderCompressStream(self, op, &input_len, &input_ptr, &output_len, &output_ptr, encoded_size) == BROTLI_TRUE;
|
||||
}
|
||||
|
||||
pub fn write(self: *BrotliEncoderState, input: ?*[]const u8, output: ?*[]u8, total_size: ?*usize) bool {
|
||||
return compress(self, .process, input, output, total_size);
|
||||
}
|
||||
|
||||
pub fn flush(self: *BrotliEncoderState, input: ?*[]const u8, output: ?*[]u8, total_size: ?*usize) bool {
|
||||
return compress(self, .flush, input, output, total_size);
|
||||
}
|
||||
|
||||
pub fn finish(self: *BrotliEncoderState, input: ?*[]const u8, output: ?*[]u8, total_size: ?*usize) bool {
|
||||
return compress(self, .finish, input, output, total_size);
|
||||
}
|
||||
};
|
||||
|
||||
pub const BROTLI_DECODER_RESULT_ERROR: u32 = 0;
|
||||
pub const BROTLI_DECODER_RESULT_SUCCESS: u32 = 1;
|
||||
pub const BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT: u32 = 2;
|
||||
pub const BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT: u32 = 3;
|
||||
pub const BrotliDecoderResult = enum(u32) {
|
||||
@"error" = BROTLI_DECODER_RESULT_ERROR,
|
||||
success = BROTLI_DECODER_RESULT_SUCCESS,
|
||||
needs_more_input = BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT,
|
||||
needs_more_output = BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT,
|
||||
};
|
||||
pub const BROTLI_DECODER_NO_ERROR: c_int = 0;
|
||||
pub const BROTLI_DECODER_SUCCESS: c_int = 1;
|
||||
pub const BROTLI_DECODER_NEEDS_MORE_INPUT: c_int = 2;
|
||||
pub const BROTLI_DECODER_NEEDS_MORE_OUTPUT: c_int = 3;
|
||||
pub const BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE: c_int = -1;
|
||||
pub const BROTLI_DECODER_ERROR_FORMAT_RESERVED: c_int = -2;
|
||||
pub const BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE: c_int = -3;
|
||||
pub const BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET: c_int = -4;
|
||||
pub const BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME: c_int = -5;
|
||||
pub const BROTLI_DECODER_ERROR_FORMAT_CL_SPACE: c_int = -6;
|
||||
pub const BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE: c_int = -7;
|
||||
pub const BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT: c_int = -8;
|
||||
pub const BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1: c_int = -9;
|
||||
pub const BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2: c_int = -10;
|
||||
pub const BROTLI_DECODER_ERROR_FORMAT_TRANSFORM: c_int = -11;
|
||||
pub const BROTLI_DECODER_ERROR_FORMAT_DICTIONARY: c_int = -12;
|
||||
pub const BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS: c_int = -13;
|
||||
pub const BROTLI_DECODER_ERROR_FORMAT_PADDING_1: c_int = -14;
|
||||
pub const BROTLI_DECODER_ERROR_FORMAT_PADDING_2: c_int = -15;
|
||||
pub const BROTLI_DECODER_ERROR_FORMAT_DISTANCE: c_int = -16;
|
||||
pub const BROTLI_DECODER_ERROR_COMPOUND_DICTIONARY: c_int = -18;
|
||||
pub const BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET: c_int = -19;
|
||||
pub const BROTLI_DECODER_ERROR_INVALID_ARGUMENTS: c_int = -20;
|
||||
pub const BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES: c_int = -21;
|
||||
pub const BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS: c_int = -22;
|
||||
pub const BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP: c_int = -25;
|
||||
pub const BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1: c_int = -26;
|
||||
pub const BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2: c_int = -27;
|
||||
pub const BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES: c_int = -30;
|
||||
pub const BROTLI_DECODER_ERROR_UNREACHABLE: c_int = -31;
|
||||
pub const BrotliDecoderErrorCode = enum(c_int) {
|
||||
no_error = BROTLI_DECODER_NO_ERROR,
|
||||
success = BROTLI_DECODER_SUCCESS,
|
||||
needs_more_input = BROTLI_DECODER_NEEDS_MORE_INPUT,
|
||||
needs_more_output = BROTLI_DECODER_NEEDS_MORE_OUTPUT,
|
||||
error_format_exuberant_nibble = BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE,
|
||||
error_format_reserved = BROTLI_DECODER_ERROR_FORMAT_RESERVED,
|
||||
error_format_exuberant_meta_nibble = BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE,
|
||||
error_format_simple_huffman_alphabet = BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET,
|
||||
error_format_simple_huffman_same = BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME,
|
||||
error_format_cl_space = BROTLI_DECODER_ERROR_FORMAT_CL_SPACE,
|
||||
error_format_huffman_space = BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE,
|
||||
error_format_context_map_repeat = BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT,
|
||||
error_format_block_length_1 = BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1,
|
||||
error_format_block_length_2 = BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2,
|
||||
error_format_transform = BROTLI_DECODER_ERROR_FORMAT_TRANSFORM,
|
||||
error_format_dictionary = BROTLI_DECODER_ERROR_FORMAT_DICTIONARY,
|
||||
error_format_window_bits = BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS,
|
||||
error_format_padding_1 = BROTLI_DECODER_ERROR_FORMAT_PADDING_1,
|
||||
error_format_padding_2 = BROTLI_DECODER_ERROR_FORMAT_PADDING_2,
|
||||
error_format_distance = BROTLI_DECODER_ERROR_FORMAT_DISTANCE,
|
||||
error_compound_dictionary = BROTLI_DECODER_ERROR_COMPOUND_DICTIONARY,
|
||||
error_dictionary_not_set = BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET,
|
||||
error_invalid_arguments = BROTLI_DECODER_ERROR_INVALID_ARGUMENTS,
|
||||
error_alloc_context_modes = BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES,
|
||||
error_alloc_tree_groups = BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS,
|
||||
error_alloc_context_map = BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP,
|
||||
error_alloc_ring_buffer_1 = BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1,
|
||||
error_alloc_ring_buffer_2 = BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2,
|
||||
error_alloc_block_type_trees = BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES,
|
||||
error_unreachable = BROTLI_DECODER_ERROR_UNREACHABLE,
|
||||
_,
|
||||
|
||||
pub fn code(this: @This()) []const u8 {
|
||||
return switch (this) {
|
||||
.error_format_exuberant_nibble => "BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE",
|
||||
.error_format_reserved => "BROTLI_DECODER_ERROR_FORMAT_RESERVED",
|
||||
.error_format_exuberant_meta_nibble => "BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE",
|
||||
.error_format_simple_huffman_alphabet => "BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET",
|
||||
.error_format_simple_huffman_same => "BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME",
|
||||
.error_format_cl_space => "BROTLI_DECODER_ERROR_FORMAT_CL_SPACE",
|
||||
.error_format_huffman_space => "BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE",
|
||||
.error_format_context_map_repeat => "BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT",
|
||||
.error_format_block_length_1 => "BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1",
|
||||
.error_format_block_length_2 => "BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2",
|
||||
.error_format_transform => "BROTLI_DECODER_ERROR_FORMAT_TRANSFORM",
|
||||
.error_format_dictionary => "BROTLI_DECODER_ERROR_FORMAT_DICTIONARY",
|
||||
.error_format_window_bits => "BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS",
|
||||
.error_format_padding_1 => "BROTLI_DECODER_ERROR_FORMAT_PADDING_1",
|
||||
.error_format_padding_2 => "BROTLI_DECODER_ERROR_FORMAT_PADDING_2",
|
||||
.error_format_distance => "BROTLI_DECODER_ERROR_FORMAT_DISTANCE",
|
||||
.error_compound_dictionary => "BROTLI_DECODER_ERROR_COMPOUND_DICTIONARY",
|
||||
.error_dictionary_not_set => "BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET",
|
||||
.error_invalid_arguments => "BROTLI_DECODER_ERROR_INVALID_ARGUMENTS",
|
||||
.error_alloc_context_modes => "BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES",
|
||||
.error_alloc_tree_groups => "BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS",
|
||||
.error_alloc_context_map => "BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP",
|
||||
.error_alloc_ring_buffer_1 => "BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1",
|
||||
.error_alloc_ring_buffer_2 => "BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2",
|
||||
.error_alloc_block_type_trees => "BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES",
|
||||
.error_unreachable => "BROTLI_DECODER_ERROR_UNREACHABLE",
|
||||
else => "unknown Brotli decoder error",
|
||||
};
|
||||
}
|
||||
|
||||
pub fn message(this: @This()) []const u8 {
|
||||
return bun.sliceTo(BrotliDecoderErrorString(this) orelse return "", 0)[0..];
|
||||
}
|
||||
};
|
||||
pub const BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION: u32 = 0;
|
||||
pub const BROTLI_DECODER_PARAM_LARGE_WINDOW: u32 = 1;
|
||||
pub const BrotliDecoderParameter = enum(u32) {
|
||||
disable_ring_buffer_reallocation = BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION,
|
||||
large_window = BROTLI_DECODER_PARAM_LARGE_WINDOW,
|
||||
};
|
||||
pub extern fn BrotliDecoderSetParameter(state: ?*BrotliDecoderState, param: BrotliEncoderParameter, value: u32) c_int;
|
||||
pub extern fn BrotliDecoderAttachDictionary(state: ?*BrotliDecoderState, @"type": BrotliSharedDictionaryType, data_size: usize, data: [*c]const u8) c_int;
|
||||
pub extern fn BrotliDecoderCreateInstance(alloc_func: brotli_alloc_func, free_func: brotli_free_func, @"opaque": ?*anyopaque) *BrotliDecoderState;
|
||||
pub extern fn BrotliDecoderDestroyInstance(state: ?*BrotliDecoderState) void;
|
||||
pub extern fn BrotliDecoderDecompress(encoded_size: usize, encoded_buffer: [*]const u8, decoded_size: *usize, decoded_buffer: [*]u8) BrotliDecoderResult;
|
||||
pub extern fn BrotliDecoderDecompressStream(state: *BrotliDecoderState, available_in: *usize, next_in: *?[*]const u8, available_out: *usize, next_out: *?[*]u8, total_out: ?*usize) BrotliDecoderResult;
|
||||
pub extern fn BrotliDecoderHasMoreOutput(state: *const BrotliDecoderState) c_int;
|
||||
pub extern fn BrotliDecoderTakeOutput(state: *BrotliDecoderState, size: *usize) ?[*]const u8;
|
||||
pub extern fn BrotliDecoderIsUsed(state: ?*const BrotliDecoderState) c_int;
|
||||
pub extern fn BrotliDecoderIsFinished(state: ?*const BrotliDecoderState) c_int;
|
||||
pub extern fn BrotliDecoderGetErrorCode(state: ?*const BrotliDecoderState) BrotliDecoderErrorCode;
|
||||
pub extern fn BrotliDecoderErrorString(c: BrotliDecoderErrorCode) ?[*:0]const u8;
|
||||
pub extern fn BrotliDecoderVersion() u32;
|
||||
pub const brotli_decoder_metadata_start_func = ?*const fn (?*anyopaque, usize) callconv(.C) void;
|
||||
pub const brotli_decoder_metadata_chunk_func = ?*const fn (?*anyopaque, [*c]const u8, usize) callconv(.C) void;
|
||||
pub extern fn BrotliDecoderSetMetadataCallbacks(state: ?*BrotliDecoderState, start_func: brotli_decoder_metadata_start_func, chunk_func: brotli_decoder_metadata_chunk_func, @"opaque": ?*anyopaque) void;
|
||||
pub const BROTLI_TRUE = @as(c_int, 1);
|
||||
pub const BROTLI_FALSE = @as(c_int, 0);
|
||||
pub const BROTLI_UINT32_MAX = ~@import("std").zig.c_translation.cast(u32, @as(c_int, 0));
|
||||
pub const BROTLI_SIZE_MAX = ~@import("std").zig.c_translation.cast(usize, @as(c_int, 0));
|
||||
pub const SHARED_BROTLI_MIN_DICTIONARY_WORD_LENGTH = @as(c_int, 4);
|
||||
pub const SHARED_BROTLI_MAX_DICTIONARY_WORD_LENGTH = @as(c_int, 31);
|
||||
pub const SHARED_BROTLI_NUM_DICTIONARY_CONTEXTS = @as(c_int, 64);
|
||||
pub const SHARED_BROTLI_MAX_COMPOUND_DICTS = @as(c_int, 15);
|
||||
pub const BROTLI_LAST_ERROR_CODE = BROTLI_DECODER_ERROR_UNREACHABLE;
|
||||
pub const BrotliSharedDictionaryStruct = struct_BrotliSharedDictionaryStruct;
|
||||
|
||||
pub const BROTLI_MODE_GENERIC: u32 = 0;
|
||||
pub const BROTLI_MODE_TEXT: u32 = 1;
|
||||
pub const BROTLI_MODE_FONT: u32 = 2;
|
||||
pub const BrotliEncoderMode = enum(u32) {
|
||||
generic = BROTLI_MODE_GENERIC,
|
||||
text = BROTLI_MODE_TEXT,
|
||||
font = BROTLI_MODE_FONT,
|
||||
_,
|
||||
};
|
||||
pub const BROTLI_OPERATION_PROCESS: u32 = 0;
|
||||
pub const BROTLI_OPERATION_FLUSH: u32 = 1;
|
||||
pub const BROTLI_OPERATION_FINISH: u32 = 2;
|
||||
pub const BROTLI_OPERATION_EMIT_METADATA: u32 = 3;
|
||||
pub const BrotliEncoderOperation = enum(u32) {
|
||||
process = BROTLI_OPERATION_PROCESS,
|
||||
flush = BROTLI_OPERATION_FLUSH,
|
||||
finish = BROTLI_OPERATION_FINISH,
|
||||
emit_metadata = BROTLI_OPERATION_EMIT_METADATA,
|
||||
_,
|
||||
};
|
||||
pub const BROTLI_PARAM_MODE: u32 = 0;
|
||||
pub const BROTLI_PARAM_QUALITY: u32 = 1;
|
||||
pub const BROTLI_PARAM_LGWIN: u32 = 2;
|
||||
pub const BROTLI_PARAM_LGBLOCK: u32 = 3;
|
||||
pub const BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING: u32 = 4;
|
||||
pub const BROTLI_PARAM_SIZE_HINT: u32 = 5;
|
||||
pub const BROTLI_PARAM_LARGE_WINDOW: u32 = 6;
|
||||
pub const BROTLI_PARAM_NPOSTFIX: u32 = 7;
|
||||
pub const BROTLI_PARAM_NDIRECT: u32 = 8;
|
||||
pub const BROTLI_PARAM_STREAM_OFFSET: u32 = 9;
|
||||
pub const BrotliEncoderParameter = enum(u32) {
|
||||
mode = BROTLI_PARAM_MODE,
|
||||
quality = BROTLI_PARAM_QUALITY,
|
||||
lgwin = BROTLI_PARAM_LGWIN,
|
||||
lgblock = BROTLI_PARAM_LGBLOCK,
|
||||
disable_literal_context_modeling = BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING,
|
||||
size_hint = BROTLI_PARAM_SIZE_HINT,
|
||||
large_window = BROTLI_PARAM_LARGE_WINDOW,
|
||||
npostfix = BROTLI_PARAM_NPOSTFIX,
|
||||
ndirect = BROTLI_PARAM_NDIRECT,
|
||||
stream_offset = BROTLI_PARAM_STREAM_OFFSET,
|
||||
_,
|
||||
};
|
||||
|
||||
pub extern fn BrotliEncoderSetParameter(state: ?*BrotliEncoderState, param: BrotliEncoderParameter, value: u32) c_int;
|
||||
pub extern fn BrotliEncoderCreateInstance(alloc_func: brotli_alloc_func, free_func: brotli_free_func, ctx: ?*anyopaque) *BrotliEncoderState;
|
||||
pub extern fn BrotliEncoderDestroyInstance(state: ?*BrotliEncoderState) void;
|
||||
pub const struct_BrotliEncoderPreparedDictionaryStruct = opaque {};
|
||||
pub const BrotliEncoderPreparedDictionary = struct_BrotliEncoderPreparedDictionaryStruct;
|
||||
pub extern fn BrotliEncoderPrepareDictionary(@"type": BrotliSharedDictionaryType, data_size: usize, data: [*c]const u8, quality: c_int, alloc_func: brotli_alloc_func, free_func: brotli_free_func, @"opaque": ?*anyopaque) ?*BrotliEncoderPreparedDictionary;
|
||||
pub extern fn BrotliEncoderDestroyPreparedDictionary(dictionary: ?*BrotliEncoderPreparedDictionary) void;
|
||||
pub extern fn BrotliEncoderAttachPreparedDictionary(state: ?*BrotliEncoderState, dictionary: ?*const BrotliEncoderPreparedDictionary) c_int;
|
||||
pub extern fn BrotliEncoderMaxCompressedSize(input_size: usize) usize;
|
||||
pub extern fn BrotliEncoderCompress(quality: c_int, lgwin: c_int, mode: BrotliEncoderMode, input_size: usize, input_buffer: [*]const u8, encoded_size: *usize, encoded_buffer: [*]u8) c_int;
|
||||
pub extern fn BrotliEncoderCompressStream(state: *BrotliEncoderState, op: BrotliEncoderOperation, available_in: *usize, next_in: *?[*]const u8, available_out: *usize, next_out: *?[*]u8, total_out: ?*usize) c_int;
|
||||
pub extern fn BrotliEncoderIsFinished(state: *BrotliEncoderState) c_int;
|
||||
pub extern fn BrotliEncoderHasMoreOutput(state: *BrotliEncoderState) c_int;
|
||||
pub extern fn BrotliEncoderTakeOutput(state: *BrotliEncoderState, size: *usize) ?[*]const u8;
|
||||
pub extern fn BrotliEncoderEstimatePeakMemoryUsage(quality: c_int, lgwin: c_int, input_size: usize) usize;
|
||||
pub extern fn BrotliEncoderGetPreparedDictionarySize(dictionary: ?*const BrotliEncoderPreparedDictionary) usize;
|
||||
pub extern fn BrotliEncoderVersion() u32;
|
||||
pub const BROTLI_ENC_ENCODE_H_ = "";
|
||||
pub const BROTLI_MIN_WINDOW_BITS = @as(c_int, 10);
|
||||
pub const BROTLI_MAX_WINDOW_BITS = @as(c_int, 24);
|
||||
pub const BROTLI_LARGE_MAX_WINDOW_BITS = @as(c_int, 30);
|
||||
pub const BROTLI_MIN_INPUT_BLOCK_BITS = @as(c_int, 16);
|
||||
pub const BROTLI_MAX_INPUT_BLOCK_BITS = @as(c_int, 24);
|
||||
pub const BROTLI_MIN_QUALITY = @as(c_int, 0);
|
||||
pub const BROTLI_MAX_QUALITY = @as(c_int, 11);
|
||||
pub const BROTLI_DEFAULT_QUALITY = @as(c_int, 11);
|
||||
pub const BROTLI_DEFAULT_WINDOW = @as(c_int, 22);
|
||||
pub const BROTLI_DEFAULT_MODE = BROTLI_MODE_GENERIC;
|
||||
pub const BrotliEncoderPreparedDictionaryStruct = struct_BrotliEncoderPreparedDictionaryStruct;
|
||||
71
src/stream_tester.zig
Normal file
71
src/stream_tester.zig
Normal file
@@ -0,0 +1,71 @@
|
||||
const compress = @import("./compress.zig");
|
||||
pub const bun = @import("./bun.zig");
|
||||
const std = @import("std");
|
||||
|
||||
const Controller = compress.Controller;
|
||||
const Completion = compress.Completion;
|
||||
const Ownership = compress.Ownership;
|
||||
const Error = compress.Error;
|
||||
|
||||
pub const CLIFileStreamCompressor = struct {
|
||||
input: std.fs.File,
|
||||
output: std.fs.File,
|
||||
closed: bool = false,
|
||||
|
||||
ready_for_more: bool = false,
|
||||
has_more_output: bool = true,
|
||||
|
||||
pub fn controller(this: *CLIFileStreamCompressor) Controller {
|
||||
return Controller.init(*CLIFileStreamCompressor, this);
|
||||
}
|
||||
|
||||
pub fn onData(this: *CLIFileStreamCompressor, bytes: []const u8, _: Ownership, completion: Completion) void {
|
||||
std.debug.assert(!this.closed);
|
||||
this.output.writeAll(bytes) catch @panic("failed to write to file");
|
||||
if (completion == Completion.last) {
|
||||
this.ready_for_more = false;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn onError(this: *CLIFileStreamCompressor, err: Error) void {
|
||||
_ = err;
|
||||
std.debug.assert(!this.closed);
|
||||
// std.debug.panic("Error: {}\n{}", .{ err.code, err.message });
|
||||
}
|
||||
|
||||
pub fn onPull(this: *CLIFileStreamCompressor) void {
|
||||
this.ready_for_more = true;
|
||||
}
|
||||
|
||||
pub fn init(path: []const u8) !CLIFileStreamCompressor {
|
||||
var file = try std.fs.cwd().openFile(path, .{ .mode = .read_write });
|
||||
return CLIFileStreamCompressor{ .input = file, .output = std.io.getStdOut() };
|
||||
}
|
||||
|
||||
pub fn run(this: *CLIFileStreamCompressor, stream: *compress.Compressor) !void {
|
||||
this.ready_for_more = true;
|
||||
const ctrl = this.controller();
|
||||
|
||||
while (this.has_more_output) {
|
||||
var buffer: [64 * 1024]u8 = undefined;
|
||||
var to_read: []const u8 = buffer[0..try this.input.readAll(&buffer)];
|
||||
this.has_more_output = to_read.len != 0;
|
||||
if (this.has_more_output) {
|
||||
stream.write(to_read, ctrl);
|
||||
}
|
||||
}
|
||||
|
||||
stream.end(ctrl);
|
||||
}
|
||||
};
|
||||
|
||||
pub fn main() anyerror!void {
|
||||
const path: []const u8 = std.mem.span(std.os.argv[std.os.argv.len - 1]);
|
||||
var file_stream = try CLIFileStreamCompressor.init(path);
|
||||
var stream: *compress.Compressor = if (bun.strings.endsWith(path, ".br"))
|
||||
try compress.Compressor.init(compress.Brotli.Decoder.initWithoutOptions())
|
||||
else
|
||||
try compress.Compressor.init(compress.Brotli.Encoder.initWithoutOptions());
|
||||
|
||||
try file_stream.run(stream);
|
||||
}
|
||||
Reference in New Issue
Block a user