Skip to content

Instantly share code, notes, and snippets.

@comex
Created April 28, 2012 22:27
Show Gist options
  • Save comex/2522441 to your computer and use it in GitHub Desktop.
Save comex/2522441 to your computer and use it in GitHub Desktop.
module Main where
import Data.ByteString (ByteString, index)
import qualified Data.ByteString as BS
import Data.List
type Offset = Int
scan :: Offset -> ByteString -> [Offset]
scan off bs
| off + 2 > (BS.length bs) = []
| (bs `index` off == 0xff) && (bs `index` (off + 1) == 0xd8) = off : scan (off + 1) bs
| otherwise = scan (off + 1) bs
main :: IO ()
main = do
bs <- BS.getContents
putStrLn $ intercalate "\n" $ map show $ scan 0 bs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment