-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransform.zig
More file actions
38 lines (29 loc) · 1.1 KB
/
transform.zig
File metadata and controls
38 lines (29 loc) · 1.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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const std = @import("std");
const assert = std.debug.assert;
const Template = @import("template.zig").Template;
pub fn main() !void {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
const allocator = arena.allocator();
const args = try std.process.argsAlloc(allocator);
const file_size_max = 1 << 20; // 1 MiB
assert(args.len == 3);
const source_directory = args[1];
const destination_directory = args[2];
var dir = try std.fs.cwd().openDir(source_directory, .{ .iterate = true });
var output = try std.fs.cwd().openDir(destination_directory, .{});
defer dir.close();
defer output.close();
var walker = try dir.walk(allocator);
defer walker.deinit();
while (try walker.next()) |entry| {
if (entry.kind == .file) {
const content = try dir.readFileAlloc(
allocator,
entry.path,
file_size_max,
);
const template = try Template.write(allocator, content);
try output.writeFile(.{ .sub_path = entry.basename, .data = template });
}
}
}