hylian-modding/ModLoader64

Invalid type passed to fs.writeFileSync in PakFormat.ts

Closed this issue · 1 comments

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.
    }