aboutsummaryrefslogtreecommitdiff
path: root/lib/std/Io/Reader.zig
AgeCommit message (Collapse)Author
2025-10-08std.Io.Reader: rework peekDelimiterInclusiveAndrew Kelley
Now it's based on calling fillMore rather than an illegal aliased stream into the Reader buffer. This commit also includes a disambiguation block inspired by #25162. If `StreamTooLong` was added to `RebaseError` then this logic could be replaced by removing the exit condition from the while loop. That error code would represent when `buffer` capacity is too small for an operation, replacing the current use of asserts.
2025-10-08std.Io.Reader: fix delimiter bugsmlugg
Fix `takeDelimiter` and `takeDelimiterExclusive` tossing too many bytes (#25132) Also add/improve test coverage for all delimiter and sentinel methods, update usages of `takeDelimiterExclusive` to not rely on the fixed bug, tweak a handful of doc comments, and slightly simplify some logic. I have not fixed #24950 in this commit because I am a little less certain about the appropriate solution there. Resolves: #25132 Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2025-10-08Reader.peekDelimiterInclusive: Fix handling of `stream` implementations that ↵Ryan Liptak
return 0 Previously, the logic in peekDelimiterInclusive (when the delimiter was not found in the existing buffer) used the `n` returned from `r.vtable.stream` as the length of the slice to check, but it's valid for `vtable.stream` implementations to return 0 if they wrote to the buffer instead of `w`. In that scenario, the `indexOfScalarPos` would be given a 0-length slice so it would never be able to find the delimiter. This commit changes the logic to assume that `r.vtable.stream` can both: - return 0, and - modify seek/end (i.e. it's also valid for a `vtable.stream` implementation to rebase) Also introduces `std.testing.ReaderIndirect` which helps in being able to test against Reader implementations that return 0 from `stream`/`readVec` Fixes #25428
2025-09-20Reader.defaultReadVec: Workaround bad `r.end += r.vtable.stream()` behaviorRyan Liptak
If `r.end` is updated in the `stream` implementation, then it's possible that `r.end += ...` will behave unexpectedly. What seems to happen is that it reverts back to its value before the function call and then the increment happens. Here's a reproduction: ```zig test "fill when stream modifies `end` and returns 0" { var buf: [3]u8 = undefined; var zero_reader = infiniteZeroes(&buf); _ = try zero_reader.fill(1); try std.testing.expectEqual(buf.len, zero_reader.end); } pub fn infiniteZeroes(buf: []u8) std.Io.Reader { return .{ .vtable = &.{ .stream = stream, }, .buffer = buf, .end = 0, .seek = 0, }; } fn stream(r: *std.Io.Reader, _: *std.Io.Writer, _: std.Io.Limit) std.Io.Reader.StreamError!usize { @memset(r.buffer[r.seek..], 0); r.end = r.buffer.len; return 0; } ``` When `fill` is called, it will call into `vtable.readVec` which in this case is `defaultReadVec`. In `defaultReadVec`: - Before the `r.end += r.vtable.stream` line, `r.end` will be 0 - In `r.vtable.stream`, `r.end` is modified to 3 and it returns 0 - After the `r.end += r.vtable.stream` line, `r.end` will be 0 instead of the expected 3 Separating the `r.end += stream();` into two lines fixes the problem (and this separation is done elsewhere in `Reader` so it seems possible that this class of bug has been encountered before). Potentially related issues: - https://github.com/ziglang/zig/issues/4021 - https://github.com/ziglang/zig/issues/12064
2025-08-30Merge pull request #25077 from ziglang/GenericReaderAndrew Kelley
std.Io: delete GenericReader, AnyReader, FixedBufferStream; and related API breakage
2025-08-30Revert "std.Io.Reader: work around llvm backend bug"Andrew Kelley
This reverts commit 530cc2c1111699d9d02ad9ebef94efa6b99f5205. The compiler bug has been fixed.
2025-08-30rework std.Io.Writer.Allocating to support runtime-known alignmentAndrew Kelley
Also, breaking API changes to: * std.fs.Dir.readFileAlloc * std.fs.Dir.readFileAllocOptions
2025-08-29std.Io: delete GenericReaderAndrew Kelley
and delete deprecated alias std.io
2025-08-28std.debug.Pdb: migrate more towards new Reader APIAndrew Kelley
There was some bug in this branch, and rather than diagnosing it, I fully finished porting over to new Reader API. Did it fix the bug?
2025-08-28std.Io.Reader: work around llvm backend bugAndrew Kelley
tracked by #25067 and I already have a fix cooking in another branch
2025-08-28fix not discarding delimiterAndrew Kelley
perhaps these APIs have the defaults backwards, eh?
2025-08-28update more to avoid GenericWriterAndrew Kelley
2025-08-28Reader.appendRemaining: Take ownership of the full allocated sliceRyan Liptak
Before this commit, calling appendRemaining with an ArrayList where list.items.len != list.capacity could result in illegal behavior if the Writer.Allocating resized the list during the appendRemaining call. Fixes #25057
2025-08-19never advance seek position in `std.Io.Reader.peekDelimiterExclusive` (#24899)Rohlem
* extend std.Io.Reader.peekDelimiterExclusive test to repeat successful end-of-stream path (fails) * fix std.Io.Reader.peekDelimiterExclusive to not advance seek position in successful end-of-stream path
2025-08-16Merge pull request #24874 from ziglang/tls-clientAndrew Kelley
std: more reliable HTTP and TLS networking
2025-08-16Compilation: remove last instance of deprecatedReaderAndrew Kelley
This also makes initStreaming preemptively disable file size checking.
2025-08-16std: more reliable HTTP and TLS networkingAndrew Kelley
* std.Io.Reader: fix confused semantics of rebase. Before it was ambiguous whether it was supposed to be based on end or seek. Now it is clearly based on seek, with an added assertion for clarity. * std.crypto.tls.Client: fix panic due to not enough buffer size available. Also, avoid unnecessary rebasing. * std.http.Reader: introduce max_head_len to limit HTTP header length. This prevents crash in underlying reader which may require a minimum buffer length. * std.http.Client: choose better buffer sizes for streams and TLS client. Crucially, the buffer shared by HTTP reader and TLS client needs to be big enough for all http headers *and* the max TLS record size. Bump HTTP header size default from 4K to 8K. fixes #24872 I have noticed however that there are still fetch problems
2025-08-15std.compress.zstd.Decompress fixesAndrew Kelley
* std.Io.Reader: appendRemaining no longer supports alignment and has different rules about how exceeding limit. Fixed bug where it would return success instead of error.StreamTooLong like it was supposed to. * std.Io.Reader: simplify appendRemaining and appendRemainingUnlimited to be implemented based on std.Io.Writer.Allocating * std.Io.Writer: introduce unreachableRebase * std.Io.Writer: remove minimum_unused_capacity from Allocating. maybe that flexibility could have been handy, but let's see if anyone actually needs it. The field is redundant with the superlinear growth of ArrayList capacity. * std.Io.Writer: growingRebase also ensures total capacity on the preserve parameter, making it no longer necessary to do ensureTotalCapacity at the usage site of decompression streams. * std.compress.flate.Decompress: fix rebase not taking into account seek * std.compress.zstd.Decompress: split into "direct" and "indirect" usage patterns depending on whether a buffer is provided to init, matching how flate works. Remove some overzealous asserts that prevented buffer expansion from within rebase implementation. * std.zig: fix readSourceFileToAlloc returning an overaligned slice which was difficult to free correctly. fixes #24608
2025-08-08Merge pull request #24740 from ziglang/http-plus-fixesAndrew Kelley
fetch, tls, and http fixes
2025-08-08Io.Reader fix defaultReadVecIgor Anić
Running tar.pipeToFileSystem compressed_mingw_includes.tar file from #24732 finishes in infinite loop calling defaultReadVec with: r.seek = 1024 r.end = 1024 r.buffer.len = 1024 first.len = 512 that combination calls vtable.stream with 0 capacity writer and loops forever. Comment is to use whichever has larger capacity, and this fix reflects that.
2025-08-07std.crypto.tls.Client: always write to bufferAndrew Kelley
simplifies the logic & makes it respect limit
2025-08-07std.Io.Reader: fix appendRemainingUnlimitedAndrew Kelley
Now it avoids mutating `r` unnecessarily, allowing the `ending` Reader to work.
2025-08-07std.crypto.tls: rework for new std.Io APIAndrew Kelley
2025-08-07Merge pull request #24199 from Justus2308/24106-fmt-castsMatthew Lugg
zig fmt: canonicalize nested cast builtin order
2025-08-06std.Io.Reader: use readVec for fill functionsAndrew Kelley
readVec has two updated responsibilities: 1. it must respect any existing already buffered data. 2. it must write to the buffer if data is empty
2025-08-03zig fmt: apply new cast builtin orderJustus Klausecker
2025-07-31std.Io.Reader: don't set end to zeroAndrew Kelley
because it may be used as a ring buffer
2025-07-31std: match readVec fn prototype exactlyAndrew Kelley
this is not necessary according to zig language, but works around a flaw in the C backend
2025-07-31fetch: update API usageAndrew Kelley
2025-07-31std.compress.zstd.Decompress: implement discard and readVecAndrew Kelley
2025-07-31compiler: update to new flate APIAndrew Kelley
2025-07-31std.Io: delete BitReaderAndrew Kelley
2025-07-31std.Io.Reader: fix readVec at endAndrew Kelley
2025-07-30std.Io.Reader: introduce readVec back into the VTableAndrew Kelley
simplifies and fixes things addresses a subset of #24608
2025-07-29std.Io.Reader: make fillUnbuffered respect prexisting bufferAndrew Kelley
addresses only one usage pattern in #24608
2025-07-26std.Io.Reader: add rebase to the vtableAndrew Kelley
This eliminates a footgun and special case handling with fixed buffers, as well as allowing decompression streams to keep a window in the output buffer.
2025-07-25std.Io: add "preserve" variants to Reader/WriterAndrew Kelley
2025-07-25std: rework zstd for new I/O APIAndrew Kelley
This passes tests but it doesn't provide as big a window size as is required to decompress larger streams. The next commit in this branch will work towards that, without introducing an additional buffer.
2025-07-23std.Io.poll: update to new I/O APIAndrew Kelley
2025-07-22std.tar: update to new I/O APIAndrew Kelley
2025-07-20std.Io.Reader: fix takeStruct/peekStruct packedAndrew Kelley
closes #24516
2025-07-20Merge pull request #24488 from ziglang/moreAndrew Kelley
std.zig: finish updating to new I/O API
2025-07-19std.Io.Writer: fix writeSliceSwapAndrew Kelley
tried to be too clever, wrote bad code
2025-07-19std.Io.Reader: remove aggressive assert from `fill`Andrew Kelley
with `.fixed("")` you should still be able to do `fill(1)` and have it return error.EndOfStream.
2025-07-17std.Io.Reader: fix readSliceShort with smaller buffer than ReaderAndrew Kelley
closes #24443
2025-07-17std.Io.Reader: update OneByteReader usage to std.testing.ReaderAndrew Kelley
2025-07-16std.Io.Reader: fix appendRemaining harderAndrew Kelley
ensure that it issues a stream call that includes the buffer to detect the end when needed, but otherwise does not offer Reader buffer to append directly to the list.
2025-07-16std.Io.Reader: fix appendRemainingAndrew Kelley
it calls readVec which is a higher level function than was expected in the previous implementation
2025-07-15std.io.Reader: add more docs for rebaseAndrew Kelley
closes #24418
2025-07-15Merge pull request #24454 from ziglang/packed-struct-streamsAndrew Kelley
std.Io: handle packed structs better