Difference between revisions of "Binary IO"

From HaskellWiki
Jump to navigation Jump to search
m (link to serTH in internet archive)
(→‎Data.Binary: Added a link to System.IO)
 
(One intermediate revision by one other user not shown)
Line 8: Line 8:
 
It's very simple to use, and provides a highly efficient, pure interface
 
It's very simple to use, and provides a highly efficient, pure interface
 
to binary serialisation.
 
to binary serialisation.
  +
  +
For just writing binary data to file, use
  +
* [http://hackage.haskell.org/package/base-4.6.0.1/docs/System-IO.html#g:21 System.IO]
  +
  +
It is a part of the base package, so it comes with [[GHC]].
   
 
A tutorial:
 
A tutorial:
   
  +
* [[Serialisation and compression with Data Binary]]
* [[Serialisation_and_compression_with_Data_Binary]]
 
   
See also [[DealingWithBinaryData]]
+
See also [[Dealing with binary data]]
   
 
== Other libraries ==
 
== Other libraries ==
   
 
* JeremyShaw's update of HalDaume's NewBinary package (Cabalized): http://www.n-heptane.com/nhlab/repos/NewBinary
 
* JeremyShaw's update of HalDaume's NewBinary package (Cabalized): http://www.n-heptane.com/nhlab/repos/NewBinary
* [http://www.cse.unsw.edu.au/~dons/fps.html Data.ByteString] (Cabalised) also provides byte level operations, and is used in some applications for binary IO
+
* [http://hackage.haskell.org/package/bytestring Data.ByteString] (Cabalised) also provides byte level operations, and is used in some applications for binary IO
* [http://www.cs.helsinki.fi/u/ekarttun/SerTH/ SerTH], [http://web.archive.org/web/20080123105519/http://www.cs.helsinki.fi/u/ekarttun/SerTH/ archived page] the TH version (sort of) of NewBinary.
+
* [http://web.archive.org/web/20080123105519/http://www.cs.helsinki.fi/u/ekarttun/SerTH/ SerTH], the TH version (sort of) of NewBinary.
 
* PeterSimons's BlockIO package (Cabalized): http://cryp.to/blockio/
 
* PeterSimons's BlockIO package (Cabalized): http://cryp.to/blockio/
 
* JohnGoerzen's MissingH package (Cabalized): http://quux.org/devel/missingh
 
* JohnGoerzen's MissingH package (Cabalized): http://quux.org/devel/missingh

Latest revision as of 19:03, 23 October 2013

Data.Binary

There are a number of binary I/O libraries available for Haskell. The best to use is the new, semi-standard Data.Binary library:

   * Data.Binary

It's very simple to use, and provides a highly efficient, pure interface to binary serialisation.

For just writing binary data to file, use

   * System.IO

It is a part of the base package, so it comes with GHC.

A tutorial:

   * Serialisation and compression with Data Binary

See also Dealing with binary data

Other libraries

For very simple serialisation, use read and show.

If you have simple binary IO requirements, then Data.ByteString might be easiest -- you get a List-like interface to packed byte arrays (interface documented here). For more complex serialisation, Data.Binary would be preferred.