Skip to content

Instantly share code, notes, and snippets.

@anacrolix
Created May 4, 2018 04:15
Show Gist options
  • Save anacrolix/8fd254a6aa7f4211e44ee3e1664d2661 to your computer and use it in GitHub Desktop.
Save anacrolix/8fd254a6aa7f4211e44ee3e1664d2661 to your computer and use it in GitHub Desktop.
bytesRange :: Wai.Request -> FileLength -> (Integer, Integer)
bytesRange r l = fromMaybe (0,l) $
(\case
ByteRangeFrom f -> (f, l-f)
ByteRangeFromTo f t -> (f, t-f+1)
ByteRangeSuffix s -> (l-s,s)
) <$> (requestHeaderRange r >>= parseByteRanges >>= listToMaybe)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment