Ticket #4046 (closed proposal: fixed)

Opened 3 years ago

Last modified 3 years ago

Add System.IO.hGetBufSome

Reported by: simonmar Owned by:
Priority: normal Milestone: 7.0.1
Component: libraries/base Version: 6.12.2
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty:
Test Case: Blocked By:
Blocking: Related Tickets:

Description

I'd like to add the following function to System.IO, alongside hGetBuf and hGetBufNonBlocking:

-- | 'hGetBufSome' @hdl buf count@ reads data from the handle @hdl@
-- into the buffer @buf@.  If there is any data available to read,
-- then 'hGetBufSome' returns it immediately; it only blocks if there
-- is no data to be read.
--
-- It returns the number of bytes actually read.  This may be zero if
-- EOF was reached before any data was read (or if @count@ is zero).
--
-- 'hGetBufSome' never raises an EOF exception, instead it returns a value
-- smaller than @count@.
--
-- If the handle is a pipe or socket, and the writing end
-- is closed, 'hGetBufSome' will behave as if EOF was reached.
--
-- 'hGetBufSome' ignores the prevailing 'TextEncoding' and 'NewlineMode'
-- on the 'Handle', and reads bytes directly.

We need it to properly fix #4041 and #3808. It corresponds more closely to the semantics of Unix read(), and I've found this to be the most useful low-level API for reading in practice.

In the long term we'd like to provide a better binary I/O API, and we might even get around to doing that before 6.14.1, but if not we'll need this.

Deadline: 2 weeks.

Change History

Changed 3 years ago by simonmar

  • status changed from new to closed
  • resolution set to fixed

Done.

Thu May 20 02:35:38 PDT 2010  Simon Marlow <marlowsd@gmail.com>
  * export hGetBufSome (#4046)
Note: See TracTickets for help on using tickets.