I'm in the process of making this function more reliable. For instance, it should probably reject something when there are these errors (which might actually lead to them being reported), and wait until the write stream is closed before resolving. :)