|
1 | 1 | {-# LANGUAGE PackageImports #-}
|
2 | 2 |
|
3 | 3 | module Codec.Archive.Tar.PackAscii
|
4 |
| - ( packAscii |
5 |
| - , toPosixString |
| 4 | + ( toPosixString |
6 | 5 | , fromPosixString
|
7 | 6 | , posixToByteString
|
8 | 7 | , byteToPosixString
|
9 | 8 | ) where
|
10 | 9 |
|
11 |
| -import qualified Data.ByteString.Char8 as BS.Char8 |
| 10 | +import Data.ByteString (ByteString) |
12 | 11 | import qualified Data.ByteString.Short as Sh
|
13 |
| -import Data.Char |
14 |
| -import GHC.Stack |
15 | 12 | import System.IO.Unsafe (unsafePerformIO)
|
16 | 13 | import "os-string" System.OsString.Posix (PosixString)
|
17 | 14 | import qualified "os-string" System.OsString.Posix as PS
|
18 | 15 | import qualified "os-string" System.OsString.Internal.Types as PS
|
19 | 16 |
|
20 |
| --- | We should really migrate to @OsPath@ from @filepath@ package, |
21 |
| --- but for now let's not corrupt data silently. |
22 |
| -packAscii :: HasCallStack => FilePath -> BS.Char8.ByteString |
23 |
| -packAscii xs |
24 |
| - | all isAscii xs = BS.Char8.pack xs |
25 |
| - | otherwise = error $ "packAscii: only ASCII filenames are supported, but got " ++ xs |
26 |
| - |
27 | 17 | toPosixString :: FilePath -> PosixString
|
28 | 18 | toPosixString = unsafePerformIO . PS.encodeFS
|
29 | 19 |
|
30 | 20 | fromPosixString :: PosixString -> FilePath
|
31 | 21 | fromPosixString = unsafePerformIO . PS.decodeFS
|
32 | 22 |
|
33 |
| -posixToByteString :: PosixString -> BS.Char8.ByteString |
| 23 | +posixToByteString :: PosixString -> ByteString |
34 | 24 | posixToByteString = Sh.fromShort . PS.getPosixString
|
35 | 25 |
|
36 |
| -byteToPosixString :: BS.Char8.ByteString -> PosixString |
| 26 | +byteToPosixString :: ByteString -> PosixString |
37 | 27 | byteToPosixString = PS.PosixString . Sh.toShort
|
0 commit comments