Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: DvdGiessen/micropython
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: DvdGiessen/micropython
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: bufferedreaderwriter
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on May 14, 2025

  1. py/modio: Handle partial writes on BufferedWriter.

    To simplify the logic create bufwriter_do_write. This function keeps
    track of the data left on self->len and, if a partial write happens,
    this function uses memmove to move the remaining data back to the
    beginning of the buffer.
    
    This allows simplifying bufwriter_write and bufwriter_flush significantly.
    
    bufwriter_flush now only needs to call this function if the buffer has
    some data stored and check for any error codes.
    Additionally, if the buffer is only partially flushed we notify the user
    too (so that they know there might be data left).
    
    bufwriter_write now just needs to call this function whenever the buffer
    gets full and copy the input into the buffer.
    It will return when either no data is written at all or when all of the
    input is consumed. In the case of a partial write it returns exactly the
    amount of data which was written.
    
    Additionally allow caching of errors to better handle partial writes.
    Until now if an error occurred during the write, the error would be
    raised and the caller had no way to know if any data was written at all
    (for example in prior calls if more than one block of data was passed as
    input). Now when we have written out some data and an error happens, we
    reset the buffer to the state it would have if it did not contain the
    data that was not written (and which was not buffered previously), and
    then, we return the data that was written (if any) or raise an error if
    no data from the input was written.
    
    This allows the programmer better control of writes. In particular, the
    programmer will know exactly how much of its last input data was written,
    consequently allowing it to handle whatever data left to be written in
    a better way.
    
    Signed-off-by: Francisco Blas (klondike) Izquierdo Riera <[email protected]>
    klondi authored and DvdGiessen committed May 14, 2025
    Configuration menu
    Copy the full SHA
    92aaf70 View commit details
    Browse the repository at this point in the history
  2. py/modio: Implement BufferedReader.

    Some times there is a need for a BufferedReader in a way similar to how
    BufferedWritter works. A clear example is when using an underlying device
    requiring aligned reads, but a less clear example is when using
    deflate.DeflateIO which will do only 1-byte reads and can become
    crippling quickly when the underlying object is a python implemented
    stream instead of a native one.
    
    The BufferedReader will only attempt to do full-buffer reads and
    ensures word-alignment in a way similar to how the writer does.
    Similarly, it will also hide any errors when partial reads happen to
    ensure that any data copied so far can be returned first.
    
    Signed-off-by: Francisco Blas (klondike) Izquierdo Riera <[email protected]>
    klondi authored and DvdGiessen committed May 14, 2025
    Configuration menu
    Copy the full SHA
    2c4d1db View commit details
    Browse the repository at this point in the history
Loading