mirror of
https://github.com/boxgaming/qbjs.git
synced 2024-09-20 04:24:45 +00:00
Merge pull request #47 from FellippeHeitor/main
Tweaks and improvements to file operations
This commit is contained in:
commit
d4c1f03a0f
1 changed files with 19 additions and 3 deletions
22
qb.js
22
qb.js
|
@ -1064,6 +1064,12 @@ var QB = new function() {
|
|||
};
|
||||
|
||||
this.sub_Close = function(fh) {
|
||||
if (!fh) {
|
||||
for (const key in _fileHandles) {
|
||||
delete _fileHandles[key];
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!_fileHandles[fh]) {
|
||||
throw new Error("Invalid file handle");
|
||||
}
|
||||
|
@ -2441,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") {
|
||||
|
@ -2489,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
|
||||
|
|
Loading…
Reference in a new issue