         if(count == -1) {
             throw IOException.ErrorReadingFromStream(error: stream.streamError, description: description)
         }
-        
-        data.append(contentsOf: buffer[0 ..< count])
+
+        var skipBytes = 0
         
         if(firstData) {
             firstData = false
-            try analyzeBOM()
-        }
+            skipBytes = try analyzeBOM()
+        }
+
+        data.append(contentsOf: buffer[skipBytes ..< count])
     }
     
     /**

        self.streamDescription = description ?? stream.description
        self.firstData = true

        self.data = [UInt8]()
        self.buffer = [UInt8](repeating: 0, count: self.bufferSize)
        
        self.dataUnitSize = {


        //read in chunks
        var index = dataUnitSize
        var startIndex = 0
        
        while(startIndex + index < data.count)
        {
            //try to read 0..<index from the data as String
            //if it is not enough, we will increment the chunk size
            while(startIndex + index < data.count)
            {
                let chunk = data[startIndex ..< startIndex + index]
                if let  string = String(bytes: chunk, encoding: encoding),
                        string.characters.count > 0
                {
