1
1
Fork 0
mirror of https://github.com/boxgaming/qbjs.git synced 2024-09-19 20:14:58 +00:00

Allow GET to read from a file into a STRING

```dim a$
open "test.txt" for binary as #1
a$=space$(lof(1))
get #1,,a$
print a$
close
```
This commit is contained in:
Fellippe Heitor 2023-06-01 01:21:37 -03:00
parent 1f20565471
commit 71fb48c14b

16
qb.js
View file

@ -2447,11 +2447,16 @@ var QB = new function() {
return;
}
else {
valueObj.value = _readDataElement(fh, position, type);
if (type == "STRING") {
var bytestoread = String(value).length;
} else {
var bytestoread = 0;
}
valueObj.value = _readDataElement(fh, position, type, bytestoread);
}
};
function _readDataElement(fh, position, type) {
function _readDataElement(fh, position, type, bytestoread) {
var vfs = GX.vfs();
var data = null;
if (type == "SINGLE") {
@ -2495,7 +2500,12 @@ var QB = new function() {
return (new DataView(data)).getUint32(0, true);
}
else if (type == "STRING") {
throw new Error("Unsupported data type: " + type);
if (bytestoread > 0) {
data = vfs.readData(fh.file, position, bytestoread);
fh.offset = position + data.byteLength;
return String.fromCharCode.apply(null, new Uint8Array(data));
}
return '';
}
else if (type == "_BIT" || type == "_UNSIGNED _BIT") {
// mimicking QB64 error message here