[commit: Cabal] master: Read/write binary files using ByteString without .Char8 modules (24a5fcd)
Ian Lynagh
igloo at earth.li
Fri Jun 24 01:48:22 CEST 2011
Repository : ssh://darcs.haskell.org//srv/darcs/packages/Cabal
On branch : master
http://hackage.haskell.org/trac/ghc/changeset/24a5fcda55114ede81d5fc68cb64e94818db65e3
>---------------------------------------------------------------
commit 24a5fcda55114ede81d5fc68cb64e94818db65e3
Author: Duncan Coutts <duncan at haskell.org>
Date: Mon Oct 22 22:21:15 2007 +0000
Read/write binary files using ByteString without .Char8 modules
ByteString.Char8 treats files as text files, which are really different
on windows. We were getting CRLF translation in Windows which was messing
everything up, like saving & reading the index file.
So now only use BS.Char8 where necessary.
>---------------------------------------------------------------
cabal-install/Hackage/Index.hs | 7 ++++---
cabal-install/Hackage/Tar.hs | 15 ++++++++-------
cabal-install/Hackage/Update.hs | 2 +-
3 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/cabal-install/Hackage/Index.hs b/cabal-install/Hackage/Index.hs
index 2a324df..b302fc3 100644
--- a/cabal-install/Hackage/Index.hs
+++ b/cabal-install/Hackage/Index.hs
@@ -18,8 +18,9 @@ import Hackage.Tar
import Prelude hiding (catch)
import Control.Exception (catch, Exception(IOException))
-import qualified Data.ByteString.Lazy.Char8 as BS
-import Data.ByteString.Lazy.Char8 (ByteString)
+import qualified Data.ByteString.Lazy as BS
+import qualified Data.ByteString.Lazy.Char8 as BS.Char8
+import Data.ByteString.Lazy (ByteString)
import System.FilePath ((</>), takeExtension, splitDirectories, normalise)
import System.IO (hPutStrLn, stderr)
import System.IO.Error (isDoesNotExistError)
@@ -48,7 +49,7 @@ parseRepoIndex repo s =
if takeExtension (tarFileName hdr) == ".cabal"
then case splitDirectories (normalise (tarFileName hdr)) of
[pkgname,vers,_] ->
- let descr = case parsePackageDescription (BS.unpack content) of
+ let descr = case parsePackageDescription (BS.Char8.unpack content) of
ParseOk _ d -> d
_ -> error $ "Couldn't read cabal file "
++ show (tarFileName hdr)
diff --git a/cabal-install/Hackage/Tar.hs b/cabal-install/Hackage/Tar.hs
index f2c8046..a7ab5e1 100644
--- a/cabal-install/Hackage/Tar.hs
+++ b/cabal-install/Hackage/Tar.hs
@@ -3,8 +3,9 @@ module Hackage.Tar (TarHeader(..), TarFileType(..),
readTarArchive, extractTarArchive,
extractTarGzFile, gunzip) where
-import qualified Data.ByteString.Lazy.Char8 as BS
-import Data.ByteString.Lazy.Char8 (ByteString)
+import qualified Data.ByteString.Lazy as BS
+import qualified Data.ByteString.Lazy.Char8 as BS.Char8
+import Data.ByteString.Lazy (ByteString)
import Data.Bits ((.&.))
import Data.Char (ord)
import Data.Int (Int8, Int64)
@@ -134,11 +135,11 @@ checkChkSum :: ByteString -> Int -> Bool
checkChkSum hdr s = s == chkSum hdr' || s == signedChkSum hdr'
where
-- replace the checksum with spaces
- hdr' = BS.concat [BS.take 148 hdr, BS.replicate 8 ' ', BS.drop 156 hdr]
+ hdr' = BS.concat [BS.take 148 hdr, BS.Char8.replicate 8 ' ', BS.drop 156 hdr]
-- tar.info says that Sun tar is buggy and
-- calculates the checksum using signed chars
- chkSum = BS.foldl' (\x y -> x + ord y) 0
- signedChkSum = BS.foldl' (\x y -> x + (ordSigned y)) 0
+ chkSum = BS.Char8.foldl' (\x y -> x + ord y) 0
+ signedChkSum = BS.Char8.foldl' (\x y -> x + (ordSigned y)) 0
ordSigned :: Char -> Int
ordSigned c = fromIntegral (fromIntegral (ord c) :: Int8)
@@ -156,7 +157,7 @@ getBytes :: Int64 -> Int64 -> ByteString -> ByteString
getBytes off len = BS.take len . BS.drop off
getByte :: Int64 -> ByteString -> Char
-getByte off bs = BS.index bs off
+getByte off bs = BS.Char8.index bs off
getString :: Int64 -> Int64 -> ByteString -> String
-getString off len = BS.unpack . BS.takeWhile (/='\0') . getBytes off len
+getString off len = BS.Char8.unpack . BS.Char8.takeWhile (/='\0') . getBytes off len
diff --git a/cabal-install/Hackage/Update.hs b/cabal-install/Hackage/Update.hs
index 48a8da2..4ea6342 100644
--- a/cabal-install/Hackage/Update.hs
+++ b/cabal-install/Hackage/Update.hs
@@ -18,7 +18,7 @@ import Hackage.Types
import Hackage.Fetch
import Hackage.Tar
-import qualified Data.ByteString.Lazy.Char8 as BS
+import qualified Data.ByteString.Lazy as BS
import System.FilePath (dropExtension)
import Text.Printf
More information about the Cvs-libraries
mailing list