[Pkg-haskell-commits] [SCM] haskell-testpack branch, master, updated. debian/1.0.2-1-4-gb0d6b36
John Goerzen
jgoerzen at complete.org
Fri Apr 23 14:44:56 UTC 2010
The following commit has been merged in the master branch:
commit 5aaa9607ca6600dec04023dfb41ddaf2488db5b4
Author: John Goerzen <jgoerzen at complete.org>
Date: Wed Oct 20 22:19:13 2004 +0100
Added hCopy stuff
Keywords:
(jgoerzen at complete.org--projects/missingh--head--1.0--patch-84)
diff --git a/ChangeLog b/ChangeLog
index 34bfbf0..df1f698 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,21 @@
# arch-tag: automatic-ChangeLog--jgoerzen at complete.org--projects/missingh--head--1.0
#
+2004-10-20 16:19:13 GMT John Goerzen <jgoerzen at complete.org> patch-84
+
+ Summary:
+ Added hCopy stuff
+ Revision:
+ missingh--head--1.0--patch-84
+
+
+ new files:
+ libsrc/MissingH/Network.hs
+
+ modified files:
+ ChangeLog libsrc/MissingH/IO.hs
+
+
2004-10-20 15:43:27 GMT John Goerzen <jgoerzen at complete.org> patch-83
Summary:
diff --git a/libsrc/MissingH/IO.hs b/libsrc/MissingH/IO.hs
index 0919239..9da1bc6 100644
--- a/libsrc/MissingH/IO.hs
+++ b/libsrc/MissingH/IO.hs
@@ -35,7 +35,7 @@ Written by John Goerzen, jgoerzen\@complete.org
module MissingH.IO(-- * Entire File\/Handle Utilities
-- ** Opened Handle Data Copying
- hLineCopy, lineCopy,
+ hCopy, hCopyProgress, hLineCopy, lineCopy,
-- ** Disk File Data Copying
copyFileLinesToFile,
-- * Line Processing Utilities
@@ -49,6 +49,7 @@ module MissingH.IO(-- * Entire File\/Handle Utilities
import System.IO.Unsafe
import System.IO
+import Data.List
{- | Given a list of strings, output a line containing each item, adding
newlines as appropriate. The list is not expected to have newlines already.
@@ -137,6 +138,43 @@ hLineInteract finput foutput func =
lines <- hGetLines finput
hPutStrLns foutput (func lines)
+{- | Copies from one handle to another in raw mode (using
+hGetContents).
+-}
+hCopy :: Handle -> Handle -> IO ()
+hCopy hin hout = do
+ c <- hGetContents hin
+ hPutStr hout c
+
+{- | Copies from one handle to another in raw mode (using hGetContents).
+Takes a function to provide progress updates to the user.
+-}
+
+hCopyProgress :: Integral a => Handle -- ^ Input handle
+ -> Handle -- ^ Output handle
+ -> (Maybe a -> Integer -> Bool -> IO ()) -- ^ Progress function -- the bool is always False unless this is the final call
+ -> Int -- Block size
+ -> Maybe a -- Estimated file size (passed to func)
+ -> IO Integer -- Number of bytes copied
+hCopyProgress hin hout func bsize estsize =
+ let copyFunc :: String -> Integer -> IO Integer
+ copyFunc [] count = return count
+ copyFunc indata count =
+ let block = take bsize indata
+ remainder = drop bsize indata
+ newcount = count + (genericLength block)
+ in
+ do
+ hPutStr hout block
+ func estsize count False
+ copyFunc remainder newcount
+ in
+ do
+ c <- hGetContents hin
+ bytes <- copyFunc c 0
+ func estsize bytes True
+ return bytes
+
{- | Copies from one handle to another in text mode (with lines).
Like 'hBlockCopy', this implementation is nice:
diff --git a/libsrc/MissingH/Threads.hs b/libsrc/MissingH/Network.hs
similarity index 60%
copy from libsrc/MissingH/Threads.hs
copy to libsrc/MissingH/Network.hs
index 5332e61..c278b1a 100644
--- a/libsrc/MissingH/Threads.hs
+++ b/libsrc/MissingH/Network.hs
@@ -1,4 +1,4 @@
-{- arch-tag: Thread utilities main file
+{- arch-tag: Network utilities main file
Copyright (C) 2004 John Goerzen <jgoerzen at complete.org>
This program is free software; you can redistribute it and/or modify
@@ -17,37 +17,22 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-}
{- |
- Module : MissingH.Threads
+ Module : MissingH.Network
Copyright : Copyright (C) 2004 John Goerzen
License : GNU GPL, version 2 or above
Maintainer : John Goerzen,
Maintainer : jgoerzen at complete.org
Stability : provisional
- Portability: portable
+ Portability: systems with networking
-This module provides various helpful utilities for dealing with threads.
+This module provides various helpful utilities for dealing with networking
Written by John Goerzen, jgoerzen\@complete.org
-}
-module MissingH.Threads(-- * I\/O utilities
- runInThread
+module MissingH.Network(
)
where
-import Control.Concurrent
-
-{- | Takes a IO action and a function. The IO action will be called in a
-separate thread. When it is completed, the specified function is called with
-its result. This is a simple way of doing callbacks. -}
-
-runInThread :: IO a -> (a -> IO b) -> IO ThreadId
-runInThread action callback =
- let computation :: IO ()
- computation = do
- x <- action
- callback x
- return ()
- in
- forkIO computation
+-- nothing yet
\ No newline at end of file
--
haskell-testpack
More information about the Pkg-haskell-commits
mailing list