-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathgen_test.zig
More file actions
24 lines (19 loc) · 1 KB
/
Copy pathgen_test.zig
File metadata and controls
24 lines (19 loc) · 1 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
const std = @import("std");
const compat = @import("src/compat.zig");
const testpdf = @import("src/testpdf.zig");
pub fn main() !void {
var gpa = compat.generalPurposeAllocator();
defer _ = gpa.deinit();
const allocator = gpa.allocator();
// Zig 0.16 file I/O requires an Io implementation. Keep this local to the
// standalone generator instead of adopting the richer process.Init entrypoint.
var threaded: if (@hasDecl(std.process, "Init")) std.Io.Threaded else void = if (@hasDecl(std.process, "Init")) .init(allocator, .{}) else {};
defer if (@hasDecl(std.process, "Init")) threaded.deinit();
if (@hasDecl(std.process, "Init")) compat.setIo(threaded.io());
const pdf_data = try testpdf.generateMinimalPdf(allocator, "Hello from zpdf!");
defer allocator.free(pdf_data);
const file = try compat.createFileCwd("test.pdf");
defer compat.closeFile(file);
try compat.writeAllFile(file, pdf_data);
std.debug.print("Generated test.pdf ({} bytes)\n", .{pdf_data.len});
}