         self.stream = stream
         self.encoding = encoding
         
-        //make the buffer size a number aligned to 4 bytes
-        self.bufferSize = Int(max(bufferSize, MINIMUM_BUFFER_SIZE) / 4) * 4
+        self.dataUnitSize = {
+            switch encoding {
+            case String.Encoding.utf32,
+                 String.Encoding.utf32LittleEndian,
+                 String.Encoding.utf32BigEndian:
+                return 4
+            case String.Encoding.utf16,
+                 String.Encoding.utf16LittleEndian,
+                 String.Encoding.utf16BigEndian:
+                return 2
+            default:
+                return 1
+            }
+        }()
+        
+        //make the buffer size a number aligned to dataUnitSize bytes
+        self.bufferSize = Int(max(bufferSize, MINIMUM_BUFFER_SIZE) / dataUnitSize) * dataUnitSize
         
         self.streamDescription = description ?? stream.description
         self.firstData = true

    let stream:                 InputStream
    let streamDescription:      String
    let bufferSize:             Int

    var data:                   Data
    var buffer:                 [UInt8]

            return nil
        }

        if let  string = String(data: data, encoding: encoding),
                string.characters.count > 0
        {
            data.removeAll()
            return string
        } else {
            var size = data.count - dataUnitSize
            while(size > 0) {
                
                if let  string = String(bytes: data[0 ..< size], encoding: encoding),
                    string.characters.count > 0
                {
                    data.removeSubrange(0 ..< size)
                    return string
                }

                size -= dataUnitSize
            }
            
        }

        return ""
    }
    
