about summary refs log tree commit diff
path: root/src/libstd/io/buffered.rs
AgeCommit message (Collapse)AuthorLines
2019-04-26Use "capacity" as parameter name in with_capacity() methodsMatthias Geier-7/+7
Closes #60271.
2019-04-11Make BufWriter use get_mut instead of manipulating inner in Write implementationChris Gregory-2/+2
get_mut allows us to abstract over the implementation detail of inner being optional.
2019-03-31libstd: deny(elided_lifetimes_in_paths)Mazdak Farrokhzad-4/+4
2019-03-28Rollup merge of #59474 - czipperz:bufwriter-fix-link-capitalization, r=CentrilMazdak Farrokhzad-2/+2
Fix link capitalization in documentation of std::io::BufWriter.
2019-03-27Fix link capitalization in documentation of std::io::BufWriter.Chris Gregory-2/+2
2019-03-27Document that `std::io::BufReader` discards contents on dropChris Gregory-0/+4
Resolves #55546
2019-03-21Auto merge of #58913 - Milack27:patch_buf_reader, r=joshtriplettbors-2/+45
Add new test case for possible bug in BufReader When reading a large chunk from a BufReader, if all the bytes from the buffer have been already consumed, the internal buffer is bypassed entirely. However, it is not invalidated, and it's possible to access its contents using the `seek_relative` method, because it tries to reuse the existing buffer.
2019-03-06Fix buffer invalidation at BufReader.read_vectoredAndré Vicente Milack-9/+11
2019-03-06Fix buffer invalidation for BufReadAndré Vicente Milack-2/+43
There are two moments when a BufRead object needs to empty it's internal buffer: - In a seek call; - In a read call when all data in the internal buffer had been already consumed and the output buffer has a greater or equal size than the internal buffer. In both cases, the buffer was not being properly emptied, but only marked as consumed (self.pos = self.cap). That should be no problem if the inner reader is only Read, but if it is Seek as well, then it's possible to access the data in the buffer by using the seek_relative method. In order to prevent this from happening, both self.pos and self.cap should be set to 0. Two test cases were added to detect that failure: - test_buffered_reader_invalidated_after_read - test_buffered_reader_invalidated_after_seek Both tests are very similar to each other. The inner reader contains the following data: [5, 6, 7, 0, 1, 2, 3, 4]. The buffer capacity is 3 bytes. - First, we call fill_buffer, which loads [5, 6, 7] into the internal buffer, and then consume those 3 bytes. - Then we either read the 5 remaining bytes in a single read call or we move to the end of the stream by calling seek. In both cases the buffer should be emptied to prevent the previous data [5, 6, 7] from being read. - We now call seek_relative(-2) and read two bytes, which should give us the last 2 bytes of the stream: [3, 4]. Before this commit, the the seek_relative method would consider that we're still in the range of the internal buffer, so instead of fetching data from the inner reader, it would return the two last bytes that were incorrectly still in the buffer: [6, 7]. Therefore, the test would fail. Now, when seek_relative is called the buffer is empty. So the expected data [3, 4] is fetched from the inner reader and the test passes.
2019-03-05Auto merge of #58423 - nox:relax-bounds-buf-reader, r=dtolnaybors-0/+2
Relax Read bounds on a bunch of BufReader<R> methods
2019-02-28libstd => 2018Taiki Endo-11/+10
2019-02-26Auto merge of #58357 - sfackler:vectored-io, r=alexcrichtonbors-2/+31
Add vectored read and write support This functionality has lived for a while in the tokio ecosystem, where it can improve performance by minimizing copies. r? @alexcrichton
2019-02-20Rollup merge of #58553 - scottmcm:more-ihle, r=Centrilkennytm-1/+1
Use more impl header lifetime elision Inspired by seeing explicit lifetimes on these two: - https://doc.rust-lang.org/nightly/std/slice/struct.Iter.html#impl-FusedIterator - https://doc.rust-lang.org/nightly/std/primitive.u32.html#impl-Not And a follow-up to https://github.com/rust-lang/rust/pull/54687, that started using IHLE in libcore. Most of the changes in here fall into two big categories: - Removing lifetimes from common traits that can essentially never user a lifetime from an input (particularly `Drop`, `Debug`, and `Clone`) - Forwarding impls that are only possible because the lifetime doesn't matter (like `impl<R: Read + ?Sized> Read for &mut R`) I omitted things that seemed like they could be more controversial, like the handful of iterators that have a `Item: 'static` despite the iterator having a lifetime or the `PartialEq` implementations [where the flipped one cannot elide the lifetime](https://internals.rust-lang.org/t/impl-type-parameter-aliases/9403/2?u=scottmcm). I also removed two lifetimes that turned out to be completely unused; see https://github.com/rust-lang/rust/issues/41960#issuecomment-464557423
2019-02-17Use more impl header lifetime elisionScott McMurray-1/+1
There are two big categories of changes in here - Removing lifetimes from common traits that can essentially never user a lifetime from an input (particularly `Drop` & `Debug`) - Forwarding impls that are only possible because the lifetime doesn't matter (like `impl<R: Read + ?Sized> Read for &mut R`) I omitted things that seemed like they could be more controversial, like the handful of iterators that have a `Item: 'static` despite the iterator having a lifetime or the `PartialEq` implementations where the flipped one cannot elide the lifetime.
2019-02-13impl Deref/DerefMut for IoVec typesSteven Fackler-2/+2
Returning &'a mut [u8] was unsound, and we may as well just have them directly deref to their slices to make it easier to work with them.
2019-02-13Add vectored read and write supportSteven Fackler-2/+31
This functionality has lived for a while in the tokio ecosystem, where it can improve performance by minimizing copies.
2019-02-13Relax Read bounds on a bunch of BufReader<R> methodsAnthony Ramine-0/+2
2019-02-10tests: doc commentsAlexander Regueiro-4/+4
2018-12-25Remove licensesMark Rousskov-10/+0
2018-12-17deny intra-doc link resolution failures in libstdAndy Russell-1/+4
2018-12-04Replace usages of `..i + 1` ranges with `..=i`.Corey Farwell-1/+1
2018-11-02Fix compile errors in testJonathan Behrens-9/+9
2018-11-02Suggested editsJonathan Behrens-24/+24
2018-11-02Add some testsJonathan Behrens-11/+20
2018-11-02Add BufWriter::buffer methodJonathan Behrens-0/+19
2018-09-06Fix invalid urlsGuillaume Gomez-4/+2
2018-08-19Fix typos found by codespell.Matthias Krüger-1/+1
2018-07-30Remove unstable and deprecated APIsSimon Sapin-46/+0
2018-07-26State default capacity for BufReader/BufWriterJonathan Behrens-2/+4
2018-07-11simplify assertionsAndy Russell-5/+4
2018-07-08rework `LineWriter` exampleAndy Russell-10/+24
The original example didn't check the return value of `write()`, didn't flush the writer, and didn't properly demonstrate the buffering. Fixes #51621.
2018-04-15Deprecate Read::chars and char::decode_utf8Simon Sapin-0/+2
Per FCP: * https://github.com/rust-lang/rust/issues/27802#issuecomment-377537778 * https://github.com/rust-lang/rust/issues/33906#issuecomment-377534308
2018-04-05Rollup merge of #49594 - mbrubeck:docs, r=steveklabnikkennytm-0/+12
Add some performance guidance to std::fs and std::io docs Adds more documentation about performance to various "read" functions in `fs` and `io`, and to `BufReader`/`BufWriter`, with the goal of helping developers choose the best option for a given task.
2018-04-03Add performance notes to BufReader/BufWriter docsMatt Brubeck-0/+12
2018-04-02Fix typoRolf van de Krol-1/+1
2018-03-28Remove hidden `foo` functions from doc examples; use `Termination` trait.Corey Farwell-109/+110
Fixes https://github.com/rust-lang/rust/issues/49233.
2018-03-18Add BufReader::bufferSteven Fackler-1/+29
This subsumes the need for an explicit is_empty function, and provides access to the buffered data itself which has been requested from time to time.
2018-02-17fix more typos found by codespell.Matthias Krüger-1/+1
2018-01-15Rollup merge of #47330 - bmusin:patch-2, r=shepmasterkennytm-4/+4
fix off-by-one error Fixes https://github.com/rust-lang/rust/issues/47325.
2018-01-14Auto merge of #46832 - Diggsey:bufread-cheaper-seek, r=alexcrichtonbors-0/+46
BufRead: Only flush the internal buffer if seeking outside of it. Fixes #31100 r? @dtolnay
2018-01-13Add note to documentationDiggory Blake-0/+4
2018-01-13Implement "seek_relative"Diggory Blake-0/+42
2018-01-13fix off-by-one errorBulat Musin-4/+4
2018-01-02Document when LineWriter flushes; document errors for into_inner.Corey Farwell-0/+11
Fixes https://github.com/rust-lang/rust/issues/42468.
2017-12-21docs: do not call integer overflows as underflowsTrevor Spiteri-1/+1
2017-10-18Implement is_empty() for BufReaderJonathan Behrens-0/+25
2017-08-15use field init shorthand EVERYWHEREZack M. Davis-1/+1
Like #43008 (f668999), but _much more aggressive_.
2017-07-20Remove mut where possibleEvan Cameron-10/+10
2017-07-09Add warning to BufWriter documentationJohn Gallagher-1/+5
2017-06-20Add `Read::initializer`.Steven Fackler-6/+16
This is an API that allows types to indicate that they can be passed buffers of uninitialized memory which can improve performance.