| author | |
| committer | |
| log | abed0f5129c5e03fce61c5c48cdc4bb396805ce2 |
| tree | 2801f2b1ddf7413528e19040a79c4492d361b7d6 |
| parent | a3efdd7279179de9591e62cab38bafdafd7e4814 |
this is now redundant2 files changed, 0 insertions(+), 58 deletions(-)
lib/std/Io.zig-3| ... | @@ -471,8 +471,6 @@ pub const changeDetectionStream = @import("Io/change_detection_stream.zig").chan | ... | @@ -471,8 +471,6 @@ pub const changeDetectionStream = @import("Io/change_detection_stream.zig").chan |
| 471 | pub const FindByteWriter = @import("Io/find_byte_writer.zig").FindByteWriter; | 471 | pub const FindByteWriter = @import("Io/find_byte_writer.zig").FindByteWriter; |
| 472 | pub const findByteWriter = @import("Io/find_byte_writer.zig").findByteWriter; | 472 | pub const findByteWriter = @import("Io/find_byte_writer.zig").findByteWriter; |
| 473 | 473 | ||
| 474 | pub const BufferedAtomicFile = @import("Io/buffered_atomic_file.zig").BufferedAtomicFile; | ||
| 475 | |||
| 476 | pub const tty = @import("Io/tty.zig"); | 474 | pub const tty = @import("Io/tty.zig"); |
| 477 | 475 | ||
| 478 | /// A Writer that doesn't write to anything. | 476 | /// A Writer that doesn't write to anything. |
| ... | @@ -895,7 +893,6 @@ test { | ... | @@ -895,7 +893,6 @@ test { |
| 895 | _ = Writer; | 893 | _ = Writer; |
| 896 | _ = @import("Io/bit_reader.zig"); | 894 | _ = @import("Io/bit_reader.zig"); |
| 897 | _ = @import("Io/bit_writer.zig"); | 895 | _ = @import("Io/bit_writer.zig"); |
| 898 | _ = @import("Io/buffered_atomic_file.zig"); | ||
| 899 | _ = @import("Io/buffered_reader.zig"); | 896 | _ = @import("Io/buffered_reader.zig"); |
| 900 | _ = @import("Io/buffered_writer.zig"); | 897 | _ = @import("Io/buffered_writer.zig"); |
| 901 | _ = @import("Io/counting_writer.zig"); | 898 | _ = @import("Io/counting_writer.zig"); |
lib/std/Io/buffered_atomic_file.zig deleted-55| ... | @@ -1,55 +0,0 @@ | ||
| 1 | const std = @import("../std.zig"); | ||
| 2 | const mem = std.mem; | ||
| 3 | const fs = std.fs; | ||
| 4 | const File = std.fs.File; | ||
| 5 | |||
| 6 | pub const BufferedAtomicFile = struct { | ||
| 7 | atomic_file: fs.AtomicFile, | ||
| 8 | file_writer: File.Writer, | ||
| 9 | buffered_writer: BufferedWriter, | ||
| 10 | allocator: mem.Allocator, | ||
| 11 | |||
| 12 | pub const buffer_size = 4096; | ||
| 13 | pub const BufferedWriter = std.io.BufferedWriter(buffer_size, File.Writer); | ||
| 14 | pub const Writer = std.io.GenericWriter(*BufferedWriter, BufferedWriter.Error, BufferedWriter.write); | ||
| 15 | |||
| 16 | /// TODO when https://github.com/ziglang/zig/issues/2761 is solved | ||
| 17 | /// this API will not need an allocator | ||
| 18 | pub fn create( | ||
| 19 | allocator: mem.Allocator, | ||
| 20 | dir: fs.Dir, | ||
| 21 | dest_path: []const u8, | ||
| 22 | atomic_file_options: fs.Dir.AtomicFileOptions, | ||
| 23 | ) !*BufferedAtomicFile { | ||
| 24 | var self = try allocator.create(BufferedAtomicFile); | ||
| 25 | self.* = BufferedAtomicFile{ | ||
| 26 | .atomic_file = undefined, | ||
| 27 | .file_writer = undefined, | ||
| 28 | .buffered_writer = undefined, | ||
| 29 | .allocator = allocator, | ||
| 30 | }; | ||
| 31 | errdefer allocator.destroy(self); | ||
| 32 | |||
| 33 | self.atomic_file = try dir.atomicFile(dest_path, atomic_file_options); | ||
| 34 | errdefer self.atomic_file.deinit(); | ||
| 35 | |||
| 36 | self.file_writer = self.atomic_file.file.deprecatedWriter(); | ||
| 37 | self.buffered_writer = .{ .unbuffered_writer = self.file_writer }; | ||
| 38 | return self; | ||
| 39 | } | ||
| 40 | |||
| 41 | /// always call destroy, even after successful finish() | ||
| 42 | pub fn destroy(self: *BufferedAtomicFile) void { | ||
| 43 | self.atomic_file.deinit(); | ||
| 44 | self.allocator.destroy(self); | ||
| 45 | } | ||
| 46 | |||
| 47 | pub fn finish(self: *BufferedAtomicFile) !void { | ||
| 48 | try self.buffered_writer.flush(); | ||
| 49 | try self.atomic_file.finish(); | ||
| 50 | } | ||
| 51 | |||
| 52 | pub fn writer(self: *BufferedAtomicFile) Writer { | ||
| 53 | return .{ .context = &self.buffered_writer }; | ||
| 54 | } | ||
| 55 | }; | ||