Skip to content

Buffer.add_channel discards data #7136

@vicuna

Description

@vicuna

Original bug ID: 7136
Reporter: @yallop
Assigned to: @gasche
Status: closed (set by @xavierleroy on 2017-09-24T15:31:48Z)
Resolution: duplicate
Priority: normal
Severity: minor
Fixed in version: 4.03.0+dev / +beta1
Category: standard library
Duplicate of: #6719

Bug description

The documentation for Buffer.add_channel says:

Raise [End_of_file] if the channel contains fewer than [n]
characters. In this case, the characters are still added to
the buffer, so as to avoid loss of data.

However, when End_of_file is raised the characters are not added to the buffer:

$ cat abc.txt
abc
$ ocaml
OCaml version 4.02.3

let buf = Buffer.create 10;;

val buf : Buffer.t =

Buffer.add_channel buf (open_in "abc.txt") 10;;

Exception: End_of_file.

Buffer.contents buf;;

  • : string = ""

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions