Rewrite writeToTemporaryFileWithName so that it returns the
NSURL or sets an NSError out param, rather than using onSuccess /
onFailure callbacks.  This code is single-threaded, so the
callbacks are pointless.

Also, add an attributes parameter rather than hard-coding those
internally.
Replace NSInputStream.writeToFile with writeToFileAndNSData.

This will return the NSData that was put in the file.  If the
file can't be written (e.g. because the screen is locked) then
you'll get the data but without the file being created.

As part of this, change NSData.dataWithContentsOfStream to take
an NSError out parameter and improve its error handling throughout.