Skip to content

Buffer.add_channel is unusable #6719

@vicuna

Description

@vicuna

Original bug ID: 6719
Reporter: @c-cube
Assigned to: @gasche
Status: closed (set by @xavierleroy on 2016-12-07T10:47:32Z)
Resolution: fixed
Priority: normal
Severity: feature
Fixed in version: 4.03.0+dev / +beta1
Category: standard library
Tags: junior_job
Has duplicate: #7136
Monitored by: @hcarty

Bug description

Buffer.add_channel behavior is flawed. In case the channel contains less than [n] bytes (where [n] is the last parameter to [Buffer.add_channel buf chan n]), some data is consumed but not read, and lost forever if the channel isn't seekable.

This makes it almost unusable in my opinion (and it looks like it's not used in trunk, as "grep -r Buffer.add_channel" shows).

Steps to reproduce

1/ echo "hello" > /tmp/some_file

2/ utop

let buf = Buffer.create 256 in
let ic = open_in "/tmp/some_file" in
(try Buffer.add_channel buf ic 256 with End_of_file -> ());
Buffer.contents buf

We obtain an empty string. In practice, unless we need how much bytes to read exactly beforehand, we just consume data from the in_channel and discard it. It makes writing a simple procedure to read all data from a channel into a Buffer impossible (except by reading char by char).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions