diff options
| author | daurnimator <quae@daurnimator.com> | 2020-11-19 02:10:14 +1100 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-01-11 16:47:48 -0700 |
| commit | 8695b9fbe781ea030bafb4f6272202b9115ba46b (patch) | |
| tree | 0438310f2c5a1c77e9bfc1532e315a7a8c2bf581 /lib/std | |
| parent | 0ab8ae944cd2b48c783c4ca8963997b6af207d5e (diff) | |
| download | zig-8695b9fbe781ea030bafb4f6272202b9115ba46b.tar.gz zig-8695b9fbe781ea030bafb4f6272202b9115ba46b.zip | |
std: use reader.skipBytes to avoid infinite loop in writeFileAllUnseekable
skipBytes correctly handles EOF for us
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/fs/file.zig | 13 |
1 files changed, 3 insertions, 10 deletions
diff --git a/lib/std/fs/file.zig b/lib/std/fs/file.zig index faf3687a4c..7acbc9e2f6 100644 --- a/lib/std/fs/file.zig +++ b/lib/std/fs/file.zig @@ -698,7 +698,7 @@ pub const File = struct { header_count: usize = 0, }; - pub const WriteFileError = ReadError || WriteError; + pub const WriteFileError = ReadError || error{EndOfStream} || WriteError; pub fn writeFileAll(self: File, in_file: File, args: WriteFileOptions) WriteFileError!void { return self.writeFileAllSendfile(in_file, args) catch |err| switch (err) { @@ -722,16 +722,9 @@ pub const File = struct { try self.writevAll(headers); + try in_file.reader().skipBytes(args.in_offset, .{ .buf_size = 4096 }); + var buffer: [4096]u8 = undefined; - { - var index: usize = 0; - // Skip in_offset bytes. - while (index < args.in_offset) { - const ask = math.min(buffer.len, args.in_offset - index); - const amt = try in_file.read(buffer[0..ask]); - index += amt; - } - } const in_len = args.in_len orelse math.maxInt(u64); var index: usize = 0; while (index < in_len) { |
