         i)))
 
   (chars-to-str [_ string-buffer chars-length]
+    "Converts character codes to characters and appends them to a string buffer
+
+     string-buffer (StringBuffer) - Google String buffer to append characters to
+     chars-length (int) - The number of characters we are appending"
     (loop [i 0]
       (when (< i chars-length)
         (do
           (.append string-buffer (.fromCharCode js/String (aget read-codes i)))
           (recur (inc i))))))
 
-  (get-buffer [_] buffer)
+  (get-buffer [_]
+    "Gets the string buffer"
+    buffer)
 
   (read-utf8-chars [sr string-buffer offset length]
+    "Reads in a string buffer and appends the characters to a string
+
+     string-buffer (StringBuffer) Google string buffer we'll append characters to
+     offset (int) - Starting point to read the string buffer
+     length (int) - The number of bytes to read"
     (let [str-length (.bytes-to-codes sr offset length)]
       (.chars-to-str sr string-buffer str-length))))
 
 (defn make-string-reader []
+  "Convience method for making a string reader"
   (StringReader. (js/Uint8Array. 65536) (make-array 21846)))
 
 (def ^{:doc "Marker for the endianess of bytestreams"}

          (recur (inc i) (+ buf-pos byte-size)))
          #js [i buf-pos]))))

  (string-chunk-utf8
    [sw s start total-str-length buffer]
    (let [str-length (Math/min 21846 (- total-str-length start))
          buf-length (Math/min 65536 (* 3 str-length))]
      (do
        (.string-to-codes sw s start (+ start str-length))
        (.write-str-bytes sw str-length buf-length))))

  (get-buffer [_] string-buffer))

(defn make-string-writer []
  (StringWriter. (make-array 16384) (js/Uint8Array. 65536)))

(deftype StringReader [buffer read-codes]
  Object
  (bytes-to-codes [_ offset length]
    (loop [i 0 pos offset]
      (if (< pos length)
        (let [ch (aget buffer pos)]

(ns longshi.fressian.utils
  "Utility data and functions for byte arrays")

(deftype
  ^{:doc
    "Object for grouping string writing methods and data together

    code-pipe ([int]) - Pre allocated buffer for holding character codes
    string-buffer ([bytes]) - Pre allocated buffer holding the converted character codes"}
  StringWriter [code-pipe string-buffer]

  Object
  (string-to-codes [_ s start-pos end-pos]
    "Converts a string into an array of character codes

    s (string) - String to convert to character codes
    start-pos (int) - The starting position to start reading from the string
    end-pos (int) - The position to stop reading from the string"
    (loop [i 0 str-pos start-pos]
      (when (< str-pos end-pos)
        (do
