Skip to content

🐛 Line endings for read with limit are missing #4

@kylewelsby

Description

@kylewelsby

When decrypting streaming and splitting files per line appears to loose \r\n or \n line endings when using Reader#read(1024).

Using without the limit doesn't lose the line endings.

Affected code

Bzip2::FFI::Reader.open(io_or_path) do |reader|
  while buffer = reader.read(1024) do
    line = buffer.split("\n")
    # process uncompressed line from the buffer
  end
end

Work around

Bzip2::FFI::Reader.open(io_or_path) do |reader|
  while buffer = reader.read do
    line = buffer.split("\n")
    # process uncompressed line from the buffer
  end
end

The issue might be somewhere around the code paths for default 4kb vs limit branch of read.
https://github.com/philr/bzip2-ffi/blob/7202391117e6709bc67404c1f55d4a3f5d3bc791/lib/bzip2/ffi/reader.rb#L311C1-L321C57

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions