Skip to content

Commit

Permalink
upd: faster directory zipping (#698)
Browse files Browse the repository at this point in the history
  • Loading branch information
solvedDev committed Nov 5, 2022
1 parent 2d77bb6 commit 9df80f7
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/components/FileSystem/Zip/ZipDirectory.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import { zip, Zippable, zipSync } from 'fflate'
import { AnyDirectoryHandle } from '../Types'
import { iterateDir } from '/@/utils/iterateDir'
import { iterateDir, iterateDirParallel } from '/@/utils/iterateDir'

export class ZipDirectory {
constructor(protected handle: AnyDirectoryHandle) {}

async package() {
async package(ignoreFolders?: Set<string>) {
let directoryContents: Zippable = {}
await iterateDir(this.handle, async (fileHandle, filePath) => {
const file = await fileHandle.getFile()
directoryContents[filePath] = new Uint8Array(
await file.arrayBuffer()
)
})
await iterateDirParallel(
this.handle,
async (fileHandle, filePath) => {
const file = await fileHandle.getFile()
directoryContents[filePath] = new Uint8Array(
await file.arrayBuffer()
)
},
ignoreFolders
)

return new Promise<Uint8Array>((resolve, reject) =>
zip(directoryContents, { level: 6 }, (error, data) => {
Expand Down

0 comments on commit 9df80f7

Please sign in to comment.