feat: added loader and appropriate build scripts
This commit is contained in:
19
unix-loader/src/gzip.zig
Normal file
19
unix-loader/src/gzip.zig
Normal file
@@ -0,0 +1,19 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn main() !void {
|
||||
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
|
||||
defer arena.deinit();
|
||||
const alloc = arena.allocator();
|
||||
|
||||
const args = try std.process.argsAlloc(alloc);
|
||||
const input_file_path = args[1];
|
||||
const output_file_path = args[2];
|
||||
|
||||
var input_file = try std.fs.cwd().openFile(input_file_path, .{});
|
||||
defer input_file.close();
|
||||
|
||||
var output_file = try std.fs.cwd().createFile(output_file_path, .{});
|
||||
defer output_file.close();
|
||||
|
||||
try std.compress.gzip.compress(input_file.reader(), output_file.writer(), .{ .level = .level_9 });
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
const std = @import("std");
|
||||
|
||||
const beacon = @embedFile("beacon");
|
||||
|
||||
fn use_beacon(message: []const u8) !void {
|
||||
_ = try std.io.getStdOut().write(message);
|
||||
}
|
||||
|
||||
export fn hash_internals() void {
|
||||
use_beacon(beacon) catch {};
|
||||
}
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
const std = @import("std");
|
||||
const testing = std.testing;
|
||||
extern fn hash_internals() void;
|
||||
|
||||
export fn add(a: i32, b: i32) i32 {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
test "basic add functionality" {
|
||||
try testing.expect(add(3, 7) == 10);
|
||||
export fn calculate_hash() void {
|
||||
hash_internals();
|
||||
}
|
||||
|
||||
@@ -1,25 +1,5 @@
|
||||
const std = @import("std");
|
||||
extern fn hash_internals() void;
|
||||
|
||||
pub fn main() !void {
|
||||
// Prints to stderr (it's a shortcut based on `std.io.getStdErr()`)
|
||||
std.debug.print("All your {s} are belong to us.\n", .{"codebase"});
|
||||
|
||||
// stdout is for the actual output of your application, for example if you
|
||||
// are implementing gzip, then only the compressed bytes should be sent to
|
||||
// stdout, not any debugging messages.
|
||||
const stdout_file = std.io.getStdOut().writer();
|
||||
var bw = std.io.bufferedWriter(stdout_file);
|
||||
const stdout = bw.writer();
|
||||
|
||||
try stdout.print("Run `zig build test` to run the tests.\n", .{});
|
||||
|
||||
try bw.flush(); // don't forget to flush!
|
||||
}
|
||||
|
||||
test "simple test" {
|
||||
var list = std.ArrayList(i32).init(std.testing.allocator);
|
||||
defer list.deinit(); // try commenting this out and see if zig detects the memory leak!
|
||||
|
||||
try list.append(42);
|
||||
try std.testing.expectEqual(@as(i32, 42), list.pop());
|
||||
pub fn main() void {
|
||||
hash_internals();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user