Hi team,
It seems a bug slipped in the latest beta:
var fh = DOpus.fsUtil().openFile('Y:\\out.txt', 'wa');
var numBytesWritten = fh.write('foobar');
DOpus.output('numBytesWritten: ' + numBytesWritten);
// prints out 7 instead of 6!
// there's a NUL char (ASCII 00) at the end
// writing from a blob instead of a string has the same problem
Thanks, the problem with writing strings will be fixed in the next beta. Note that the ability to write strings was actually only added for the first time in the previous beta.
I can't reproduce the same thing with a Blob, however, and I wouldn't have thought this would have changed (the problem was only with the newly added code for writing strings). Can you please provide some example code that exhibits that issue?
E.g., this prints 5 as you would expect:
var fh = DOpus.fsUtil().openFile('Y:\\out.txt', 'wa');
var bl = DOpus.create.blob(65, 66, 67, 68, 69);
var numBytesWritten = fh.write(bl);
DOpus.output('numBytesWritten: ' + numBytesWritten);
Ignore the Result & logger stuff, but they should be self-explanatory. I'm using Blob's not just to write & read just binary data but text data as well; come to think of it I hardly used Blob for binary data, if at all
function saveFile(path, contents) {
var fh = DOpus.fsUtil().openFile(path, 'wa');
if(fh.error !== 0) { /* removed for brevity */ }
try {
var blob = DOpus.create().blob();
blob.copyFrom(contents, 'utf8');
var numBytesWritten = fh.write(blob);
logger.snormal('Written bytes: %d, orig length: %d, path: %s', numBytesWritten, contents.length, path);
blob.free();
fh.close();
return ResultOk(numBytesWritten);
} catch(e) { /* removed for brevity */ }
}