#New IO.Writer and IO.Reader, minimal buffer piping

1 messages · Page 1 of 1 (latest)

candid fox
#

Hello i am new to zig does anyone know how could i pipe file to std-out with only one buffer used?

const std = @import("std");

const print = std.debug.print;
var buffer: [1024]u8 = undefined;
pub fn main() !void {
    const file = try std.fs.cwd().openFile("./build.zig", .{ .mode = .read_only });
    const reader = file.reader(&buffer);

    // Its not safe to use same buffer for writer and reader, so how could say solve it without additional buffer?
    const writer = std.fs.File.stdout().writer(.{});
    const written = try reader.interface.stream(&writer, .{.unlimited});
    print("Written {d}", written);
}
#

basically trying to found a way to lead chunk and direcly write it to the std-out without addtional coping between buffers

candid fox
#

i hate ai

#

nvm