Repository: pedroslopez/whatsapp-web.js
File: src/authStrategies/RemoteAuth.js (JavaScript)

Code before:
                stream.on('close', () => resolve());
                archive.finalize();
            });
        } catch (error) {
            console.log('RemoteAuth Error => compressSession: ', error);
        }
    }

    async unCompressSession() {
        try {
            var stream = fs.createReadStream(`RemoteAuth-${this.sessionName}.zip`);
            return new Promise((resolve, reject) => {
                stream.pipe(unzipper.Extract({
                    path: this.userDataDir
                }))
                    .on('error', err => reject(err))
                    .on('finish', () => resolve());
            });
        } catch (error) {
            console.log('RemoteAuth Error => unCompressSession: ', error);
        }
    }

    async deleteMetadata() {
        try {
            /* First Level */
            let sessionFiles = await fs.promises.readdir(this.userDataDir);
            for (let element of sessionFiles) {
                if (!this.requiredDirs.includes(element)) {
                    let dirElement = path.join(this.userDataDir, element);
                    let stats = await fs.promises.lstat(dirElement);
    
                    if (stats.isDirectory()) {
                        await fs.promises.rm(dirElement, {
                            recursive: true,
                            force: true
                        });
                    } else {
                        await fs.promises.unlink(dirElement);
                    }
                }
            }

            /* Second Level */
            let sessionFilesDefault = await fs.promises.readdir(`${this.userDataDir}/Default`);
            for (let element of sessionFilesDefault) {
                if (!this.requiredDirs.includes(element)) {
                    let dirElement = path.join(`${this.userDataDir}/Default`, element);
                    let stats = await fs.promises.lstat(dirElement);
    
                    if (stats.isDirectory()) {

Review comment (refactor):
These "two levels" can probably be refactored to share code since the only thing that changes is the path that `readdir` is using, e.g.:

```js
const dirs = [this.userDataDir, path.join(this.userDataDir, "Default")];
for(const metaDir of dirs) {
    const sessionFiles = await fs.promises.readdir(metaDir);
   // ...
}
```

Code after:
        return new Promise((resolve, reject) => {
            archive
                .directory(this.tempDir, false)
                .on('error', err => reject(err))
                .pipe(stream);

            stream.on('close', () => resolve());
            archive.finalize();
        });
    }

    async unCompressSession(compressedSessionPath) {
        var stream = fs.createReadStream(compressedSessionPath);
        await new Promise((resolve, reject) => {
            stream.pipe(unzipper.Extract({
                path: this.userDataDir
            }))
                .on('error', err => reject(err))
                .on('finish', () => resolve());
        });
        await fs.promises.unlink(compressedSessionPath);
    }

    async deleteMetadata() {
        const sessionDirs = [this.tempDir, path.join(this.tempDir, 'Default')];
        for (const dir of sessionDirs) {
            const sessionFiles = await fs.promises.readdir(dir);
            for (const element of sessionFiles) {
                if (!this.requiredDirs.includes(element)) {
                    const dirElement = path.join(dir, element);
                    const stats = await fs.promises.lstat(dirElement);
    
                    if (stats.isDirectory()) {
                        await fs.promises.rm(dirElement, {
                            recursive: true,
                            force: true
                        });
                    } else {
                        await fs.promises.unlink(dirElement);
                    }
                }
            }
        }
    }

    async isValidPath(path) {
        try {
            await fs.promises.access(path);
            return true;
        } catch {
            return false;