-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathcompression.zig
More file actions
29 lines (22 loc) · 1.07 KB
/
compression.zig
File metadata and controls
29 lines (22 loc) · 1.07 KB
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 std = @import("std");
const compression = @import("features/compression.zig");
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
var comp = compression.Compression.init(allocator);
const data = "Hello, this is some test data for compression!";
// Try different compression algorithms
const compressed_gzip = try comp.compress(data, .gzip);
defer allocator.free(compressed_gzip);
const compressed_deflate = try comp.compress(data, .deflate);
defer allocator.free(compressed_deflate);
// Decompress and verify
const decompressed_gzip = try comp.decompress(compressed_gzip, .gzip);
defer allocator.free(decompressed_gzip);
const decompressed_deflate = try comp.decompress(compressed_deflate, .deflate);
defer allocator.free(decompressed_deflate);
std.debug.print("Original size: {}\n", .{data.len});
std.debug.print("Gzip size: {}\n", .{compressed_gzip.len});
std.debug.print("Deflate size: {}\n", .{compressed_deflate.len});
}