Skip to content

Commit 38479bc

Browse files
committed
std: merge io.PeekStream and io.BufferedInStreamCustom
1 parent 8a5907d commit 38479bc

File tree

3 files changed

+11
-116
lines changed

3 files changed

+11
-116
lines changed

lib/std/io.zig

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,6 @@ pub const bufferedOutStream = @import("io/buffered_out_stream.zig").bufferedOutS
9898
pub const BufferedInStream = @import("io/buffered_in_stream.zig").BufferedInStream;
9999
pub const bufferedInStream = @import("io/buffered_in_stream.zig").bufferedInStream;
100100

101-
pub const PeekStream = @import("io/peek_stream.zig").PeekStream;
102-
pub const peekStream = @import("io/peek_stream.zig").peekStream;
103-
104101
pub const FixedBufferStream = @import("io/fixed_buffer_stream.zig").FixedBufferStream;
105102
pub const fixedBufferStream = @import("io/fixed_buffer_stream.zig").fixedBufferStream;
106103

@@ -151,7 +148,6 @@ test "" {
151148
_ = @import("io/fixed_buffer_stream.zig");
152149
_ = @import("io/in_stream.zig");
153150
_ = @import("io/out_stream.zig");
154-
_ = @import("io/peek_stream.zig");
155151
_ = @import("io/seekable_stream.zig");
156152
_ = @import("io/serialization.zig");
157153
_ = @import("io/stream_source.zig");

lib/std/io/buffered_in_stream.zig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ const io = std.io;
33
const assert = std.debug.assert;
44
const testing = std.testing;
55

6+
/// Creates a readable stream which buffers data
7+
/// It also supports 'un-reading' data, so that it can be read again.
8+
/// This makes look-ahead style parsing much easier.
69
pub fn BufferedInStream(comptime buffer_type: std.fifo.LinearFifoBufferType, comptime InStreamType: type) type {
710
return struct {
811
unbuffered_in_stream: InStreamType,
@@ -66,6 +69,14 @@ pub fn BufferedInStream(comptime buffer_type: std.fifo.LinearFifoBufferType, com
6669
return dest.len;
6770
}
6871

72+
pub fn putBackByte(self: *Self, byte: u8) !void {
73+
try self.putBack(&[_]u8{byte});
74+
}
75+
76+
pub fn putBack(self: *Self, bytes: []const u8) !void {
77+
try self.fifo.unget(bytes);
78+
}
79+
6980
pub fn inStream(self: *Self) InStream {
7081
return .{ .context = self };
7182
}

lib/std/io/peek_stream.zig

Lines changed: 0 additions & 112 deletions
This file was deleted.

0 commit comments

Comments
 (0)