aboutsummaryrefslogtreecommitdiff
path: root/src/http/zlib.zig
blob: 4a2e88bec70de02767e6731a672f88912fe1075a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const Lock = @import("../lock.zig").Lock;
const std = @import("std");
const MutableString = @import("../global.zig").MutableString;
const getAllocator = @import("../http_client_async.zig").getAllocator;
const ZlibPool = @This();
const Zlib = @import("../zlib.zig");
const bun = @import("../global.zig");

fn initMutableString(allocator: std.mem.Allocator) anyerror!MutableString {
    return MutableString.initEmpty(allocator);
}

const BufferPool = bun.ObjectPool(MutableString, initMutableString, false, 4);

pub fn get(allocator: std.mem.Allocator) *MutableString {
    return &BufferPool.get(allocator).data;
}

pub fn put(mutable: *MutableString) void {
    mutable.reset();
    var node = @fieldParentPtr(BufferPool.Node, "data", mutable);
    node.release();
}

pub fn decompress(compressed_data: []const u8, output: *MutableString) Zlib.ZlibError!void {
    var reader = try Zlib.ZlibReaderArrayList.init(compressed_data, &output.list, output.allocator);
    try reader.readAll();
    reader.deinit();
}