Fix fragment caching in mixed encodings scenario

To reduce ambiguity between char- and byte-based operations, explicitly
do byte operations when extracting the fragment that needs to be cached.
Add test for extracting the cache fragment with mixed encodings
Don't rely on default encoding always being ASCII-8BIT
Merge pull request #39 from github/write-fragment-fix

Fix fragment caching in mixed encoding scenario