Skip to content

Commit

Permalink
some more methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ProgrammerIn-wonderland committed Sep 19, 2024
1 parent cd1e11f commit 65b7fe9
Showing 1 changed file with 37 additions and 11 deletions.
48 changes: 37 additions & 11 deletions src/api/LocalFS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -605,9 +605,12 @@ class LocalFS extends AFSProvider<LocalFSStats> {
throw new Error("Method not implemented.");
}

fchown() {
console.error("Not implemented: fchown");
throw new Error("Method not implemented.");
fchown(fd: AnuraFD, ...rest: any[]) {
const cb = rest[3];
this.promises
.chown(fd.path!, rest[1], rest[2])
.then(() => {})
.catch((e) => cb(e));
}

chmod(path: string, ...rest: any[]) {
Expand All @@ -618,9 +621,12 @@ class LocalFS extends AFSProvider<LocalFSStats> {
.catch((e) => cb(e));
}

fchmod() {
console.error("Not implemented: fchmod");
throw new Error("Method not implemented.");
fchmod(fd: AnuraFD, ...rest: any[]) {
const cb = rest[2];
this.promises
.chmod(fd.path!, rest[1])
.then(() => {})
.catch((e) => cb(e));
}

fsync(fd: AnuraFD, callback?: (err: Error | null) => void) {
Expand Down Expand Up @@ -679,8 +685,25 @@ class LocalFS extends AFSProvider<LocalFSStats> {
});
}

read() {
console.error("Not implemented: read");
read(
fd: AnuraFD,
buffer: Uint8Array,
offset: number,
length: number,
position: number,
callback: any,
) {
(async () => {
const data: Uint8Array = await this.promises.readFile(fd.path!);
for (const num in data) {
// slow, maybe dont use this, also probably wrong
if (Number(num) + position + offset <= length)
buffer[num] = data[Number(num) + position + offset]!;
}
let nbytes = data.length;
if (nbytes > length) nbytes = length;
callback(null, nbytes);
})();
throw new Error("Method not implemented.");
}
// From here to below are not in normal nodejs
Expand Down Expand Up @@ -725,9 +748,12 @@ class LocalFS extends AFSProvider<LocalFSStats> {
throw new Error("Method not implemented.");
}

chown() {
console.error("Not implemented: chown");
throw new Error("Method not implemented.");
chown(path: string, ...rest: any[]) {
const cb = rest[3];
this.promises
.chown(path!, rest[1], rest[2])
.then(() => {})
.catch((e) => cb(e));
}

close(fd: AnuraFD, callback: (err: Error | null) => void) {
Expand Down

0 comments on commit 65b7fe9

Please sign in to comment.