@@ -64,10 +64,11 @@ putHeader entry =
64
64
LBS. fromStrict
65
65
$ BS. take 148 block
66
66
<> putOct 7 checksum
67
- <> BS.Char8. cons ' ' (BS. drop 156 block)
67
+ <> BS. cons 0x20 (BS. drop 156 block)
68
68
where
69
69
block = putHeaderNoChkSum entry
70
- checksum = BS.Char8. foldl' (\ x y -> x + ord y) 0 block
70
+ checksum :: Int
71
+ checksum = BS. foldl' (\ x y -> x + fromIntegral y) 0 block
71
72
72
73
putHeaderNoChkSum :: Entry -> BS. ByteString
73
74
putHeaderNoChkSum Entry {
@@ -86,33 +87,33 @@ putHeaderNoChkSum Entry {
86
87
, putOct 8 $ groupId ownership
87
88
, numField 12 contentSize
88
89
, putOct 12 modTime
89
- , BS.Char8. replicate 8 ' ' -- dummy checksum
90
+ , BS. replicate 8 0x20 -- dummy checksum
90
91
, putChar8 typeCode
91
92
, putPosixString 100 linkTarget
92
93
] <>
93
94
case format of
94
95
V7Format ->
95
- BS.Char8. replicate 255 ' \NUL '
96
- UstarFormat -> BS.Char8. concat
96
+ BS. replicate 255 0x00
97
+ UstarFormat -> BS. concat
97
98
[ putBString 8 ustarMagic
98
99
, putString 32 $ ownerName ownership
99
100
, putString 32 $ groupName ownership
100
101
, putOct 8 deviceMajor
101
102
, putOct 8 deviceMinor
102
103
, putPosixString 155 prefix
103
- , BS.Char8. replicate 12 ' \NUL '
104
+ , BS. replicate 12 0x00
104
105
]
105
- GnuFormat -> BS.Char8. concat
106
+ GnuFormat -> BS. concat
106
107
[ putBString 8 gnuMagic
107
108
, putString 32 $ ownerName ownership
108
109
, putString 32 $ groupName ownership
109
110
, putGnuDev 8 deviceMajor
110
111
, putGnuDev 8 deviceMinor
111
112
, putPosixString 155 prefix
112
- , BS.Char8. replicate 12 ' \NUL '
113
+ , BS. replicate 12 0x00
113
114
]
114
115
where
115
- numField :: FieldWidth -> Int64 -> BS.Char8. ByteString
116
+ numField :: FieldWidth -> Int64 -> BS. ByteString
116
117
numField w n
117
118
| n >= 0 && n < 1 `shiftL` (3 * (w - 1 ))
118
119
= putOct w n
@@ -133,24 +134,24 @@ putHeaderNoChkSum Entry {
133
134
putGnuDev w n = case content of
134
135
CharacterDevice _ _ -> putOct w n
135
136
BlockDevice _ _ -> putOct w n
136
- _ -> BS.Char8. replicate w ' \NUL '
137
+ _ -> BS. replicate w 0x00
137
138
138
139
ustarMagic , gnuMagic :: BS. ByteString
139
- ustarMagic = BS.Char8. pack " ustar\NUL 00"
140
- gnuMagic = BS.Char8. pack " ustar \NUL "
140
+ ustarMagic = BS. pack [ 0x75 , 0x73 , 0x74 , 0x61 , 0x72 , 0x00 , 0x30 , 0x30 ] -- ustar\NUL00
141
+ gnuMagic = BS. pack [ 0x75 , 0x73 , 0x74 , 0x61 , 0x72 , 0x20 , 0x20 , 0x00 ] -- ustar \NUL
141
142
142
143
-- * TAR format primitive output
143
144
144
145
type FieldWidth = Int
145
146
146
147
putBString :: FieldWidth -> BS. ByteString -> BS. ByteString
147
- putBString n s = BS. take n s <> BS.Char8. replicate (n - BS. length s) ' \NUL '
148
+ putBString n s = BS. take n s <> BS. replicate (n - BS. length s) 0x00
148
149
149
150
putPosixString :: FieldWidth -> PosixString -> BS. ByteString
150
- putPosixString n s = posixToByteString (PS. take n s) <> BS.Char8. replicate (n - PS. length s) ' \NUL '
151
+ putPosixString n s = posixToByteString (PS. take n s) <> BS. replicate (n - PS. length s) 0x00
151
152
152
153
putString :: FieldWidth -> String -> BS. ByteString
153
- putString n s = BS. take n (packAscii s) <> BS.Char8. replicate (n - length s) ' \NUL '
154
+ putString n s = BS. take n (packAscii s) <> BS. replicate (n - length s) 0x00
154
155
155
156
{-# SPECIALISE putLarge :: FieldWidth -> Int64 -> BS.ByteString #-}
156
157
putLarge :: (Bits a , Integral a ) => FieldWidth -> a -> BS. ByteString
@@ -161,9 +162,9 @@ putLarge n0 x0 = BS.Char8.pack $ '\x80' : reverse (go (n0-1) x0)
161
162
putOct :: (Integral a , Show a ) => FieldWidth -> a -> BS. ByteString
162
163
putOct n x =
163
164
let octStr = BS. take (n- 1 ) $ BS.Char8. pack $ showOct x " "
164
- in BS.Char8. replicate (n - BS. length octStr - 1 ) ' 0 '
165
+ in BS. replicate (n - BS. length octStr - 1 ) 0x30
165
166
<> octStr
166
- <> putChar8 ' \NUL '
167
+ <> BS. singleton 0x00
167
168
168
169
putChar8 :: Char -> BS. ByteString
169
170
putChar8 = BS.Char8. singleton
0 commit comments