mirror of
https://github.com/ziglang/zig.git
synced 2026-01-21 06:45:24 +00:00
std.Io: delete BufferedAtomicFile
this is now redundant
This commit is contained in:
parent
a3efdd7279
commit
abed0f5129
@ -471,8 +471,6 @@ pub const changeDetectionStream = @import("Io/change_detection_stream.zig").chan
|
||||
pub const FindByteWriter = @import("Io/find_byte_writer.zig").FindByteWriter;
|
||||
pub const findByteWriter = @import("Io/find_byte_writer.zig").findByteWriter;
|
||||
|
||||
pub const BufferedAtomicFile = @import("Io/buffered_atomic_file.zig").BufferedAtomicFile;
|
||||
|
||||
pub const tty = @import("Io/tty.zig");
|
||||
|
||||
/// A Writer that doesn't write to anything.
|
||||
@ -895,7 +893,6 @@ test {
|
||||
_ = Writer;
|
||||
_ = @import("Io/bit_reader.zig");
|
||||
_ = @import("Io/bit_writer.zig");
|
||||
_ = @import("Io/buffered_atomic_file.zig");
|
||||
_ = @import("Io/buffered_reader.zig");
|
||||
_ = @import("Io/buffered_writer.zig");
|
||||
_ = @import("Io/counting_writer.zig");
|
||||
|
||||
@ -1,55 +0,0 @@
|
||||
const std = @import("../std.zig");
|
||||
const mem = std.mem;
|
||||
const fs = std.fs;
|
||||
const File = std.fs.File;
|
||||
|
||||
pub const BufferedAtomicFile = struct {
|
||||
atomic_file: fs.AtomicFile,
|
||||
file_writer: File.Writer,
|
||||
buffered_writer: BufferedWriter,
|
||||
allocator: mem.Allocator,
|
||||
|
||||
pub const buffer_size = 4096;
|
||||
pub const BufferedWriter = std.io.BufferedWriter(buffer_size, File.Writer);
|
||||
pub const Writer = std.io.GenericWriter(*BufferedWriter, BufferedWriter.Error, BufferedWriter.write);
|
||||
|
||||
/// TODO when https://github.com/ziglang/zig/issues/2761 is solved
|
||||
/// this API will not need an allocator
|
||||
pub fn create(
|
||||
allocator: mem.Allocator,
|
||||
dir: fs.Dir,
|
||||
dest_path: []const u8,
|
||||
atomic_file_options: fs.Dir.AtomicFileOptions,
|
||||
) !*BufferedAtomicFile {
|
||||
var self = try allocator.create(BufferedAtomicFile);
|
||||
self.* = BufferedAtomicFile{
|
||||
.atomic_file = undefined,
|
||||
.file_writer = undefined,
|
||||
.buffered_writer = undefined,
|
||||
.allocator = allocator,
|
||||
};
|
||||
errdefer allocator.destroy(self);
|
||||
|
||||
self.atomic_file = try dir.atomicFile(dest_path, atomic_file_options);
|
||||
errdefer self.atomic_file.deinit();
|
||||
|
||||
self.file_writer = self.atomic_file.file.deprecatedWriter();
|
||||
self.buffered_writer = .{ .unbuffered_writer = self.file_writer };
|
||||
return self;
|
||||
}
|
||||
|
||||
/// always call destroy, even after successful finish()
|
||||
pub fn destroy(self: *BufferedAtomicFile) void {
|
||||
self.atomic_file.deinit();
|
||||
self.allocator.destroy(self);
|
||||
}
|
||||
|
||||
pub fn finish(self: *BufferedAtomicFile) !void {
|
||||
try self.buffered_writer.flush();
|
||||
try self.atomic_file.finish();
|
||||
}
|
||||
|
||||
pub fn writer(self: *BufferedAtomicFile) Writer {
|
||||
return .{ .context = &self.buffered_writer };
|
||||
}
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user