git.iko.soy/typeable/pandoc
on master help sign in
ImageSize: Avoid use of lookAhead, which is not in binary >= 0.6.
a333d97John MacFarlane
src/Text/Pandoc/ImageSize.hs+5−4
@@ -182,15 +182,16 @@ findJfifSize bs = do
182 Nothing -> fail "Did not find length record"
182 Nothing -> fail "Did not find length record"
183
183
184exifSize :: ByteString -> Maybe ImageSize
184exifSize :: ByteString -> Maybe ImageSize
185−exifSize = runGet (Just <$> exifHeader) . BL.fromChunks . (:[])
185+exifSize bs = runGet (Just <$> exifHeader bl) bl
186+ where bl = BL.fromChunks [bs]
186-- NOTE: It would be nicer to do
187-- NOTE: It would be nicer to do
187-- runGet ((Just <$> exifHeader) <|> return Nothing)
188-- runGet ((Just <$> exifHeader) <|> return Nothing)
188-- which would prevent pandoc from raising an error when an exif header can't
189-- which would prevent pandoc from raising an error when an exif header can't
189-- be parsed. But we only get an Alternative instance for Get in binary 0.6,
190-- be parsed. But we only get an Alternative instance for Get in binary 0.6,
190-- and binary 0.5 ships with ghc 7.6.
191-- and binary 0.5 ships with ghc 7.6.
191
192
192−exifHeader :: Get ImageSize
193+exifHeader :: BL.ByteString -> Get ImageSize
193−exifHeader = do
194+exifHeader hdr = do
194 _app1DataSize <- getWord16be
195 _app1DataSize <- getWord16be
195 exifHdr <- getWord32be
196 exifHdr <- getWord32be
196 unless (exifHdr == 0x45786966) $ fail "Did not find exif header"
197 unless (exifHdr == 0x45786966) $ fail "Did not find exif header"
@@ -198,7 +199,7 @@ exifHeader = do
198 unless (zeros == 0) $ fail "Expected zeros after exif header"
199 unless (zeros == 0) $ fail "Expected zeros after exif header"
199 -- beginning of tiff header -- we read whole thing to use
200 -- beginning of tiff header -- we read whole thing to use
200 -- in getting data from offsets:
201 -- in getting data from offsets:
201− tiffHeader <- lookAhead getRemainingLazyByteString
202+ let tiffHeader = BL.drop 8 hdr
202 byteAlign <- getWord16be
203 byteAlign <- getWord16be
203 let bigEndian = byteAlign == 0x4d4d
204 let bigEndian = byteAlign == 0x4d4d
204 let (getWord16, getWord32, getWord64) =
205 let (getWord16, getWord32, getWord64) =