MyNixOS website logo
Description

Simple and high performance IO toolkit for Haskell.

Simple and high performance IO toolkit for Haskell, including file system, network, ipc and more!

Z-IO

Hackage Linux Build Status MacOS Build Status Windows Build Status Docker Build Status Gitter chat

This package is part of Z.Haskell project, provides basic IO operations:

  • IO resource management, resource pool
  • File system operations
  • Network: DNS, TCP, UDP and IPC
  • Buffered input and output
  • Process management
  • Environment settings
  • High performance logger
  • High performance low resolution timer

Requirements

  • A working haskell compiler system, GHC(>=8.6), cabal-install(>=2.4), hsc2hs.
  • Tests need hspec-discover.

Example usage

> :set -XOverloadedStrings
> import Z.IO.Network
> import Z.IO.Resource
> import Z.IO.Buffered
>
> -- call getAddrInfo to perform DNS
> head <$> getAddrInfo Nothing "www.bing.com" "http"
AddrInfo {addrFlags = [AI_ADDRCONFIG,AI_V4MAPPED], addrFamily = SocketFamily 2, addrSocketType = SocketType 1, addrProtocol = ProtocolNumber 6, addrAddress = 204.79.197.200:80, addrCanonName = ""}
>
> import qualified Z.Data.Text as T
> -- send a simple HTTP request
> :{
let addr = ipv4 "13.107.21.200" 80
in withResource (initTCPClient defaultTCPClientConfig{ tcpRemoteAddr = addr}) $ \ tcp -> do
    (i, o) <- newBufferedIO tcp
    writeBuffer' o "GET http://www.bing.com HTTP/1.1\r\nHost: www.bing.com\r\n\r\n"
    readBuffer i >>= pure . T.validate
:}
"HTTP/1.1 200 OK\r\nDate: Sat, 19 Sep 2020 06:11:08 GMT\r\nContent-Length: 0\r\n\r\n"
>
> -- Start a TCP echo server, use @nc -v localhost 8080@ to test
> :{
startTCPServer defaultTCPServerConfig{
    tcpListenAddr = SocketAddrIPv4 ipv4Loopback 8080} $ \ tcp -> do
        i <- newBufferedInput tcp
        o <- newBufferedOutput tcp
        forever $ readBuffer i >>= writeBuffer o >> flushBuffer o
}
:}

Dev guide

# get code
git clone --recursive [email protected]:ZHaskell/z-io.git
cd z-io
# build
cabal build
# test
cabal run Z-IO-Test
# install
cabal install
# generate document
cabal haddock
Metadata

Version

2.0.0.0

Platforms (75)

    Darwin
    FreeBSD 13
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd13
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd13
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows