System.Posix.IO.ByteString

Hi All, I'm playing around with some low level IO and found the following function: System.Posix.IO.fdRead :: Fd -> ByteCount -> IO (String, ByteCount) Ok, close, but what if I need a ByteString instead. I then found this: System.Posix.IO.ByteString.fdRead :: Fd -> ByteCount -> IO (String, ByteCount) which is identical to the one above. The ByteString in the module name suggests it would be using ByteString instead of String? Can anyone explain this for me? Cheers, Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/

On Sat, Jan 10, 2015 at 7:15 PM, Erik de Castro Lopo
System.Posix.IO.ByteString.fdRead :: Fd -> ByteCount -> IO (String, ByteCount)
which is identical to the one above. The ByteString in the module name suggests it would be using ByteString instead of String?
Can anyone explain this for me?
The "ByteString" in the SYstem.Posix.*.ByteString modules applies to the pathnames (POSIX pathnames are byte strings, and there's lots of ways to cause problems if you insist on pretending that they are in any particular encoding), not the values being read/written, so functions like that are basically carried along just to provide a mostly compatible API. I would expect to find functions working with ByteString values under Data.ByteString. -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

On 2015-01-11 at 01:22:34 +0100, Brandon Allbery wrote: [...]
The "ByteString" in the SYstem.Posix.*.ByteString modules applies to the pathnames (POSIX pathnames are byte strings, and there's lots of ways to cause problems if you insist on pretending that they are in any particular encoding), not the values being read/written, so functions like that are basically carried along just to provide a mostly compatible API.
I would expect to find functions working with ByteString values under Data.ByteString.
However those take [Char] as FilePath argument... where would you look if you wanted to functions that used ByteStrings for both, filepaths and content? Cheers, hvr

The 'unix-bytestring' package looks like it can read a ByteString from the
file descriptor once you have it open:
http://hackage.haskell.org/package/unix-bytestring-0.3.7.2/docs/System-Posix...
Sadly both 'unix' and 'unix-bytestring' define a module named
'System.Posix.IO.ByteString', and you need functionality from both to get
your job done - 'openFd' from 'unix' and then 'fdRead' from
'unix-bytestring'.
On Sun Jan 11 2015 at 7:18:30 AM Herbert Valerio Riedel
On 2015-01-11 at 01:22:34 +0100, Brandon Allbery wrote:
[...]
The "ByteString" in the SYstem.Posix.*.ByteString modules applies to the pathnames (POSIX pathnames are byte strings, and there's lots of ways to cause problems if you insist on pretending that they are in any particular encoding), not the values being read/written, so functions like that are basically carried along just to provide a mostly compatible API.
I would expect to find functions working with ByteString values under Data.ByteString.
However those take [Char] as FilePath argument... where would you look if you wanted to functions that used ByteStrings for both, filepaths and content?
Cheers, hvr _______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries

The naming collision is unfortunate, but solvable with the PackageImports
extension.
On 06:15, Sun, Jan 11, 2015 Antoine Latter
The 'unix-bytestring' package looks like it can read a ByteString from the file descriptor once you have it open:
http://hackage.haskell.org/package/unix-bytestring-0.3.7.2/docs/System-Posix...
Sadly both 'unix' and 'unix-bytestring' define a module named 'System.Posix.IO.ByteString', and you need functionality from both to get your job done - 'openFd' from 'unix' and then 'fdRead' from 'unix-bytestring'.
On Sun Jan 11 2015 at 7:18:30 AM Herbert Valerio Riedel
wrote: On 2015-01-11 at 01:22:34 +0100, Brandon Allbery wrote:
[...]
The "ByteString" in the SYstem.Posix.*.ByteString modules applies to the pathnames (POSIX pathnames are byte strings, and there's lots of ways to cause problems if you insist on pretending that they are in any particular encoding), not the values being read/written, so functions like that are basically carried along just to provide a mostly compatible API.
I would expect to find functions working with ByteString values under Data.ByteString.
However those take [Char] as FilePath argument... where would you look if you wanted to functions that used ByteStrings for both, filepaths and content?
Cheers, hvr _______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries

John Lato
The naming collision is unfortunate, but solvable with the PackageImports extension.
That being said, given that `unix` already has a dependency on `bytestring`, is there any reason why `ByteString`-enabled `fdRead` and friends from `unix-bytestring` shouldn't just be folded into `unix`? Cheers, - Ben

Antoine Latter wrote:
The 'unix-bytestring' package looks like it can read a ByteString from the file descriptor once you have it open:
http://hackage.haskell.org/package/unix-bytestring-0.3.7.2/docs/System-Posix...
Sadly both 'unix' and 'unix-bytestring' define a module named 'System.Posix.IO.ByteString', and you need functionality from both to get your job done - 'openFd' from 'unix' and then 'fdRead' from 'unix-bytestring'.
Ah, thanks for that. In the end, I ended up using `fdReadBuf` to read the data into a buffer, followed by `unsafePackCStringFinalizer` to get a ByteString. Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/
participants (6)
-
Antoine Latter
-
Ben Gamari
-
Brandon Allbery
-
Erik de Castro Lopo
-
Herbert Valerio Riedel
-
John Lato