System.Posix.IO.ByteString

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

System.Posix.IO.ByteString

Erik de Castro Lopo-34
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/
_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: System.Posix.IO.ByteString

Brandon Allbery
On Sat, Jan 10, 2015 at 7:15 PM, Erik de Castro Lopo <[hidden email]> wrote:
    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
[hidden email]                                  [hidden email]
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net

_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: System.Posix.IO.ByteString

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
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: System.Posix.IO.ByteString

Antoine Latter-2
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-IO-ByteString.html

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 <[hidden email]> 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
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: System.Posix.IO.ByteString

John Lato-2

The naming collision is unfortunate, but solvable with the PackageImports extension.


On 06:15, Sun, Jan 11, 2015 Antoine Latter <[hidden email]> 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-IO-ByteString.html

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 <[hidden email]> 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
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: System.Posix.IO.ByteString

Erik de Castro Lopo-34
In reply to this post by Antoine Latter-2
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-IO-ByteString.html
>
> 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/
_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: System.Posix.IO.ByteString

Ben Gamari-2
In reply to this post by John Lato-2
John Lato <[hidden email]> writes:

> 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


_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries

attachment0 (482 bytes) Download Attachment