summaryrefslogtreecommitdiff
path: root/src/cmd/copy.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/copy.zig')
-rw-r--r--src/cmd/copy.zig38
1 files changed, 11 insertions, 27 deletions
diff --git a/src/cmd/copy.zig b/src/cmd/copy.zig
index 1c3c3ba..733dc47 100644
--- a/src/cmd/copy.zig
+++ b/src/cmd/copy.zig
@@ -46,36 +46,20 @@ pub const Copy = struct {
};
defer dest_file.close();
- // Read from stdin and write to file until EOF (Ctrl+Z on DOS)
- const stdin = std.io.getStdIn().reader();
+ // Read from input source and write to file until EOF (Ctrl+Z on DOS)
var line_count: u32 = 0;
+ var reader = ctx.input_reader;
while (true) {
- if (stdin.readUntilDelimiterOrEofAlloc(ctx.allocator, '\n', 4096)) |maybe_line| {
- if (maybe_line) |line| {
- defer ctx.allocator.free(line);
-
- // Check for Ctrl+Z (EOF marker)
- if (line.len == 1 and line[0] == 26) { // ASCII 26 = Ctrl+Z
- break;
- }
-
- // Remove trailing \r if present (Windows line endings)
- const clean_line = if (line.len > 0 and line[line.len - 1] == '\r')
- line[0 .. line.len - 1]
- else
- line;
-
- // Write line to file with DOS line ending
- try dest_file.writeAll(clean_line);
- try dest_file.writeAll("\r\n");
- line_count += 1;
- } else {
- // EOF reached
- break;
- }
- } else |_| {
- // Error reading input
+ if (try reader.readLine(ctx.allocator)) |line| {
+ defer ctx.allocator.free(line);
+
+ // Write line to file with DOS line ending
+ try dest_file.writeAll(line);
+ try dest_file.writeAll("\r\n");
+ line_count += 1;
+ } else {
+ // EOF reached
break;
}
}