| ... | @@ -360,6 +360,18 @@ pub fn readEnum(self: Self, comptime Enum: type, endian: std.builtin.Endian) any | ... | @@ -360,6 +360,18 @@ pub fn readEnum(self: Self, comptime Enum: type, endian: std.builtin.Endian) any |
| 360 | return E.InvalidValue; | 360 | return E.InvalidValue; |
| 361 | } | 361 | } |
| 362 | | 362 | |
| | 363 | /// Reads the stream until the end, ignoring all the data. |
| | 364 | /// Returns the number of bytes discarded. |
| | 365 | pub fn discard(self: Self) anyerror!u64 { |
| | 366 | var trash: [4096]u8 = undefined; |
| | 367 | var index: u64 = 0; |
| | 368 | while (true) { |
| | 369 | const n = try self.read(&trash); |
| | 370 | if (n == 0) return index; |
| | 371 | index += n; |
| | 372 | } |
| | 373 | } |
| | 374 | |
| 363 | const std = @import("../std.zig"); | 375 | const std = @import("../std.zig"); |
| 364 | const Self = @This(); | 376 | const Self = @This(); |
| 365 | const math = std.math; | 377 | const math = std.math; |