| ... | ... | @@ -655,6 +655,17 @@ pub fn pread(self: File, buffer: []u8, offset: u64) PReadError!usize { |
| 655 | 655 | return posix.pread(self.handle, buffer, offset); |
| 656 | 656 | } |
| 657 | 657 | |
| 658 | /// Deprecated in favor of `Reader`. |
| 659 | pub fn preadAll(self: File, buffer: []u8, offset: u64) PReadError!usize { |
| 660 | var index: usize = 0; |
| 661 | while (index != buffer.len) { |
| 662 | const amt = try self.pread(buffer[index..], offset + index); |
| 663 | if (amt == 0) break; |
| 664 | index += amt; |
| 665 | } |
| 666 | return index; |
| 667 | } |
| 668 | |
| 658 | 669 | /// See https://github.com/ziglang/zig/issues/7699 |
| 659 | 670 | pub fn readv(self: File, iovecs: []const posix.iovec) ReadError!usize { |
| 660 | 671 | if (is_windows) { |
| ... | ... | @@ -697,6 +708,14 @@ pub fn writeAll(self: File, bytes: []const u8) WriteError!void { |
| 697 | 708 | } |
| 698 | 709 | } |
| 699 | 710 | |
| 711 | /// Deprecated in favor of `Writer`. |
| 712 | pub fn pwriteAll(self: File, bytes: []const u8, offset: u64) PWriteError!void { |
| 713 | var index: usize = 0; |
| 714 | while (index < bytes.len) { |
| 715 | index += try self.pwrite(bytes[index..], offset + index); |
| 716 | } |
| 717 | } |
| 718 | |
| 700 | 719 | /// On Windows, this function currently does alter the file pointer. |
| 701 | 720 | /// https://github.com/ziglang/zig/issues/12783 |
| 702 | 721 | pub fn pwrite(self: File, bytes: []const u8, offset: u64) PWriteError!usize { |
| ... | ... | @@ -732,6 +751,31 @@ pub fn pwritev(self: File, iovecs: []posix.iovec_const, offset: u64) PWriteError |
| 732 | 751 | return posix.pwritev(self.handle, iovecs, offset); |
| 733 | 752 | } |
| 734 | 753 | |
| 754 | /// Deprecated in favor of `Writer`. |
| 755 | pub const CopyRangeError = posix.CopyFileRangeError; |
| 756 | |
| 757 | /// Deprecated in favor of `Writer`. |
| 758 | pub fn copyRange(in: File, in_offset: u64, out: File, out_offset: u64, len: u64) CopyRangeError!u64 { |
| 759 | const adjusted_len = math.cast(usize, len) orelse maxInt(usize); |
| 760 | const result = try posix.copy_file_range(in.handle, in_offset, out.handle, out_offset, adjusted_len, 0); |
| 761 | return result; |
| 762 | } |
| 763 | |
| 764 | /// Deprecated in favor of `Writer`. |
| 765 | pub fn copyRangeAll(in: File, in_offset: u64, out: File, out_offset: u64, len: u64) CopyRangeError!u64 { |
| 766 | var total_bytes_copied: u64 = 0; |
| 767 | var in_off = in_offset; |
| 768 | var out_off = out_offset; |
| 769 | while (total_bytes_copied < len) { |
| 770 | const amt_copied = try copyRange(in, in_off, out, out_off, len - total_bytes_copied); |
| 771 | if (amt_copied == 0) return total_bytes_copied; |
| 772 | total_bytes_copied += amt_copied; |
| 773 | in_off += amt_copied; |
| 774 | out_off += amt_copied; |
| 775 | } |
| 776 | return total_bytes_copied; |
| 777 | } |
| 778 | |
| 735 | 779 | /// Deprecated in favor of `Io.File.Reader`. |
| 736 | 780 | pub const Reader = Io.File.Reader; |
| 737 | 781 | |