The hunk library is designed for manipulating hunks of binary data in an efficient (and functional) style.
hunk