this repo has no description
1* Bytestrings
2
3Processing files as strings has one drawback: it tends to be slow.
4~String~ is a type synonym for ~[Char]~.
5~Char~ don't have a fixed size, because it takes several bytes to represent a character from, say, Unicode.
6
7That overhead doesn't bother us so much most of the time, but it turns out to be a liability when reading big files and manipulating them.
8That's why Haskell has *bytestrings*.
9Bytestrings are sort of like lists, only each element ir one byte (or 8 bits) in size.
10The way they handle laziness is also different.
11
12Bytestrings come in two flavors: strict and lazy ones.
13
14=Strict bytestrings= resides in *Data.ByteString* and they do away with the laziness completely.
15There are no promises involved; a strict bytestring represents a series of bytes in an array.
16You can't have things like infinite strict bytestrings.
17If you evaluate the first byte of a strict bytestring, you have to evaluate it whole.
18
19=Lazy bytestrings= resides in *Data.ByteString.Lazy*.
20They're lazy, but not quite as lazy as lists.
21Lazy bytestrings take a different approach - they are stored in chunks each chunk has a size of 64K.
22When you process a file with lazy bytestrings, it will be read chunk by chunk.
23This is cool because it won't cause the memory usage to skyrocket and the 64K probably fits neatly into your CPU's L2 cache.
24
25[[file:files/bytestringscopy.hs][Example using lazy bytrestring to copy file]]