Invalid type passed to fs.writeFileSync in PakFormat.ts
FredericHamel opened this issue · 1 comments
FredericHamel commented
In the Pak method extractAll
, the local variable data
marked as Buffer
can have an invalid type
because the method load can return an object.
extractAll(target: string): void {
for (let i = 0; i < this.pak.header.files.length; i++) {
let data: Buffer = this.load(i); // data is can be an object
// ...
fs.writeFileSync(path.resolve(path.join(target, filename)), data); //requires a String or Buffer
}
}
// this.load(index)
load(index = 0): any {
// call to PakFile.retrieve
return this.pak.retrieve(index);
}
The reason the Pak method can return because the is a call to JSON.parse
in the PakFile's retrieve
method that returns an object.
// PakFile.retrieve(index)
retrieve(index: number): any {
let d = this.header.files[index].data;
// code...
return JSON.parse(d.toString('ascii')); // this returns an object.
}
denoflionsx commented
The parse is due to its usage in the Storage API that predates the use of
paks as containers for mods. Dual typing the retrieve method and checking
it properly in extractAll is my first thought to not disrupt other usage of
retrieve.
…On Wed, Jun 3, 2020, 3:26 PM FredericHamel ***@***.***> wrote:
In the Pak method extractAll, the local variable data marked as Buffer
can have an invalid type
because the method load can return an object.
extractAll(target: string): void {
for (let i = 0; i < this.pak.header.files.length; i++) {
let data: Buffer = this.load(i); // data is can be an object
// ...
fs.writeFileSync(path.resolve(path.join(target, filename)), data); //requires a String or Buffer
}
}
// this.load(index)
load(index = 0): any {
// call to PakFile.retrieve
return this.pak.retrieve(index);
}
The reason the Pak method can return because the is a call to JSON.parse
in the PakFile's retrieve method that returns an object.
// PakFile.retrieve(index)
retrieve(index: number): any {
let d = this.header.files[index].data;
// code...
return JSON.parse(d.toString('ascii')); // this returns an object.
}
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#6>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AANZEFKAHJUKDQIWJ5IL333RU2PV7ANCNFSM4NR6SZDQ>
.