@@ -61,15 +61,15 @@ putEntry entry = case entryContent entry of
61
61
62
62
putHeader :: Entry -> LBS. ByteString
63
63
putHeader entry =
64
- LBS.Char8. pack
65
- $ take 148 block
66
- ++ putOct 7 checksum
67
- ++ ' ' : drop 156 block
64
+ LBS. fromStrict
65
+ $ BS. take 148 block
66
+ <> putOct 7 checksum
67
+ <> BS.Char8. cons ' ' ( BS. drop 156 block)
68
68
where
69
69
block = putHeaderNoChkSum entry
70
- checksum = foldl' (\ x y -> x + ord y) 0 block
70
+ checksum = BS.Char8. foldl' (\ x y -> x + ord y) 0 block
71
71
72
- putHeaderNoChkSum :: Entry -> String
72
+ putHeaderNoChkSum :: Entry -> BS. ByteString
73
73
putHeaderNoChkSum Entry {
74
74
entryTarPath = TarPath name prefix,
75
75
entryContent = content,
@@ -79,40 +79,40 @@ putHeaderNoChkSum Entry {
79
79
entryFormat = format
80
80
} =
81
81
82
- concat
82
+ BS. concat
83
83
[ putPosixString 100 name
84
84
, putOct 8 permissions
85
85
, putOct 8 $ ownerId ownership
86
86
, putOct 8 $ groupId ownership
87
87
, numField 12 contentSize
88
88
, putOct 12 modTime
89
- , replicate 8 ' ' -- dummy checksum
89
+ , BS.Char8. replicate 8 ' ' -- dummy checksum
90
90
, putChar8 typeCode
91
91
, putPosixString 100 linkTarget
92
- ] ++
92
+ ] <>
93
93
case format of
94
94
V7Format ->
95
- replicate 255 ' \NUL '
96
- UstarFormat -> concat
95
+ BS.Char8. replicate 255 ' \NUL '
96
+ UstarFormat -> BS.Char8. concat
97
97
[ putBString 8 ustarMagic
98
98
, putString 32 $ ownerName ownership
99
99
, putString 32 $ groupName ownership
100
100
, putOct 8 deviceMajor
101
101
, putOct 8 deviceMinor
102
102
, putPosixString 155 prefix
103
- , replicate 12 ' \NUL '
103
+ , BS.Char8. replicate 12 ' \NUL '
104
104
]
105
- GnuFormat -> concat
105
+ GnuFormat -> BS.Char8. concat
106
106
[ putBString 8 gnuMagic
107
107
, putString 32 $ ownerName ownership
108
108
, putString 32 $ groupName ownership
109
109
, putGnuDev 8 deviceMajor
110
110
, putGnuDev 8 deviceMinor
111
111
, putPosixString 155 prefix
112
- , replicate 12 ' \NUL '
112
+ , BS.Char8. replicate 12 ' \NUL '
113
113
]
114
114
where
115
- numField :: FieldWidth -> Int64 -> String
115
+ numField :: FieldWidth -> Int64 -> BS.Char8. ByteString
116
116
numField w n
117
117
| n >= 0 && n < 1 `shiftL` (3 * (w - 1 ))
118
118
= putOct w n
@@ -133,7 +133,7 @@ putHeaderNoChkSum Entry {
133
133
putGnuDev w n = case content of
134
134
CharacterDevice _ _ -> putOct w n
135
135
BlockDevice _ _ -> putOct w n
136
- _ -> replicate w ' \NUL '
136
+ _ -> BS.Char8. replicate w ' \NUL '
137
137
138
138
ustarMagic , gnuMagic :: BS. ByteString
139
139
ustarMagic = BS.Char8. pack " ustar\NUL 00"
@@ -143,27 +143,27 @@ gnuMagic = BS.Char8.pack "ustar \NUL"
143
143
144
144
type FieldWidth = Int
145
145
146
- putBString :: FieldWidth -> BS. ByteString -> String
147
- putBString n s = BS.Char8. unpack ( BS. take n s) ++ replicate (n - BS. length s) ' \NUL '
146
+ putBString :: FieldWidth -> BS. ByteString -> BS. ByteString
147
+ putBString n s = BS. take n s <> BS.Char8. replicate (n - BS. length s) ' \NUL '
148
148
149
- putPosixString :: FieldWidth -> PosixString -> String
150
- putPosixString n s = fromPosixString (PS. take n s) ++ replicate (n - PS. length s) ' \NUL '
149
+ putPosixString :: FieldWidth -> PosixString -> BS. ByteString
150
+ putPosixString n s = posixToByteString (PS. take n s) <> BS.Char8. replicate (n - PS. length s) ' \NUL '
151
151
152
- putString :: FieldWidth -> String -> String
153
- putString n s = take n s ++ replicate (n - length s) ' \NUL '
152
+ putString :: FieldWidth -> String -> BS. ByteString
153
+ putString n s = BS. take n (packAscii s) <> BS.Char8. replicate (n - length s) ' \NUL '
154
154
155
- {-# SPECIALISE putLarge :: FieldWidth -> Int64 -> String #-}
156
- putLarge :: (Bits a , Integral a ) => FieldWidth -> a -> String
157
- putLarge n0 x0 = ' \x80 ' : reverse (go (n0- 1 ) x0)
155
+ {-# SPECIALISE putLarge :: FieldWidth -> Int64 -> BS.ByteString #-}
156
+ putLarge :: (Bits a , Integral a ) => FieldWidth -> a -> BS. ByteString
157
+ putLarge n0 x0 = BS.Char8. pack $ ' \x80 ' : reverse (go (n0- 1 ) x0)
158
158
where go 0 _ = []
159
159
go n x = chr (fromIntegral (x .&. 0xff )) : go (n- 1 ) (x `shiftR` 8 )
160
160
161
- putOct :: (Integral a , Show a ) => FieldWidth -> a -> String
161
+ putOct :: (Integral a , Show a ) => FieldWidth -> a -> BS. ByteString
162
162
putOct n x =
163
- let octStr = take (n- 1 ) $ showOct x " "
164
- in replicate (n - length octStr - 1 ) ' 0'
165
- ++ octStr
166
- ++ putChar8 ' \NUL '
163
+ let octStr = BS. take (n- 1 ) $ BS.Char8. pack $ showOct x " "
164
+ in BS.Char8. replicate (n - BS. length octStr - 1 ) ' 0'
165
+ <> octStr
166
+ <> putChar8 ' \NUL '
167
167
168
- putChar8 :: Char -> String
169
- putChar8 c = [c]
168
+ putChar8 :: Char -> BS. ByteString
169
+ putChar8 = BS.Char8. singleton
0 commit comments