stdio: A simple and high performance IO toolkit for Haskell

[ bsd3, data, library ] [ Propose Tags ]

This package provides a simple and high performance IO toolkit for Haskell, including packed vectors, unicode texts, socket, file system, timers and more!


[Skip to Readme]

Flags

Manual Flags

NameDescriptionDefault
no-pkg-config

Don't use pkg-config to check for library dependences

Disabled
Automatic Flags
NameDescriptionDefault
integer-simple

Use the simple integer library instead of integer-gmp

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0.0, 0.1.1.0, 0.2.0.0
Change log ChangeLog.md
Dependencies base (>=4.12 && <5.0), case-insensitive (>=1.2 && <1.3), deepseq (>=1.4 && <1.5), exceptions (>=0.10 && <0.11), ghc-prim (>=0.5.3 && <=0.5.4), hashable (>=1.2 && <1.3), integer-gmp (>=0.2 && <1.1), integer-simple (>=0.1 && <0.5), primitive (>=0.6.4 && <=0.6.5), QuickCheck (>=2.10), scientific (>=0.3 && <0.4), stm (>=2.5 && <2.6), tagged (>=0.8 && <0.9), template-haskell (>=2.14 && <2.15), time (>=1.8 && <2.0), unordered-containers (>=0.2 && <0.3) [details]
License BSD-3-Clause
Copyright (c) Dong Han, 2017-2018 (c) Tao He, 2017-2019
Author Dong Han, Tao He
Maintainer winterland1989@gmail.com
Category Data
Home page https://github.com/haskell-stdio/stdio
Bug tracker https://github.com/haskell-stdio/stdio/issues
Source repo head: git clone git://github.com/haskell-stdio/stdio.git
Uploaded by winterland at 2019-05-15T10:07:35Z
Distributions
Downloads 1447 total (8 in the last 30 days)
Rating 2.25 (votes: 2) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user [build log]
All reported builds failed as of 2019-05-15 [all 2 reports]

Readme for stdio-0.2.0.0

[back to package description]

Haskell stdio: haskell standard input and output

Linux Build Status Windows Build Status

Welcome! Haskell stdio is a complete I/O toolkit powered by libuv, it features a multi-core io multiplexer and various improvements on packed data types. This project is still in infancy. Please join in!

    __  _____   _____ __ __ ________    __       _______________  ________ 
   / / / /   | / ___// //_// ____/ /   / /      / ___/_  __/ __ \/  _/ __ \
  / /_/ / /| | \__ \/ ,<  / __/ / /   / /       \__ \ / / / / / // // / / /
 / __  / ___ |___/ / /| |/ /___/ /___/ /___    ___/ // / / /_/ // // /_/ / 
/_/ /_/_/  |_/____/_/ |_/_____/_____/_____/   /____//_/ /_____/___/\____/

Install

On windows we have bundled libuv source, so no extra steps to be taken.

On *nix platforms, you should install libuv library first, you can use your distribution's package manager if available, for example:

# on debian/ubuntu, make sure to use 1.x
apt-get install libuv1-dev  libuv1

# on MacOS, we recommend brew
brew install libuv

...

Currently the minimum version requirement for libuv is v1.14. If your package manager's libuv doesn't meet this requirement, you can also build libuv from source following the guide here, e.g.

git clone https://github.com/libuv/libuv.git 
cd libuv 
git checkout tags/v1.24.0   # depend on your own need, any version >= 1.14 will work.
sh autogen.sh 
./configure 
make 
sudo make install 

After manually building and installing, you may need to modify your LIBRARY_PATH/CPATH if necessary. Now installing stdio is as easy as any other haskell packages.

cabal install stdio

Now you can fire GHCi and play around, or read the project overview, haddock.

Examples

  • hello world
import Std.IO.StdStream
import qualified Std.Data.Text as T

main = do
    -- read stdin and write to stdout, but with our new IO manager!
    input <- readLineStd
    printStd (T.validate input)
  • tcp echo server
import Std.IO.TCP
import Std.IO.Buffered
import Control.Monad

main = do
    startServer defaultServerConfig
        { serverAddr = SockAddrInet 8888 inetAny
        , serverWorker = echo
        }
  where
    echo uvs = forever $ do
        i <- newBufferedInput uvs 4096
        o <- newBufferedOutput uvs 4096
        readBuffer i >>= writeBuffer o
        flushBuffer o

Now try nc -v 127.0.0.1 8888.

  • logging
import Std.IO.Logger
import qualified Std.Data.Builder as B
import Control.Concurrent

main = withStdLogger $ do
    debug $ "hello world! PI ~=" >> B.double pi     -- debug level won't be immediately flushed
    forkIO $ do
        fatal "fatal message will trigger a log flush"
  • file system operatations
import           Std.IO.FileSystem
import           Std.IO.Resource
import           Std.IO.StdStream

main = do
    -- create a temp directory
    tempdir <- mkdtemp "temp"   
    let filename = "temp" <> "/test"
        flags = O_RDWR .|. O_CREAT      -- create if not exist
        mode = DEFAULT_MODE

    -- file is a 'Resource', use 'withResource' to automatically manage it
    withResource (initUVFile filename flags mode) $ \ f -> do
        o <- newBufferedOutput file 4096
        writeBuffer o "hello world!"
        flushBuffer o

    stat filename >>= printStd