Scripting File.Write string bug in new 12.23.1 beta

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

That's all :slight_smile:

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);
1 Like

Amazing! <3

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 :smiley:

        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);
                return ResultOk(numBytesWritten);
            } catch(e) { /* removed for brevity */ }

Cool, thanks for that. It turns out that's actually the same problem, so the same fix fixes both.

Today's new beta contains the fix: Directory Opus 12.23.2 (Beta)

1 Like

Thanks for the info. Tested successuflly! :+1: