Function create [src]
TODO when https://github.com/ziglang/zig/issues/2761 is solved
this API will not need an allocator
Prototype
pub fn create( allocator: mem.Allocator, dir: fs.Dir, dest_path: []const u8, atomic_file_options: fs.Dir.AtomicFileOptions, ) !*BufferedAtomicFile
Parameters
allocator: mem.Allocator
dir: fs.Dir
dest_path: []const u8
atomic_file_options: fs.Dir.AtomicFileOptions
Source
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.writer();
self.buffered_writer = .{ .unbuffered_writer = self.file_writer };
return self;
}