A LibArchive
class wrapping libarchive
FFI implementation.
open(archivePath: string): { archive?: Deno.UnsafePointer, errMsg?: string }
- opens archive at specified path. ReturnserrMsg
when unsuccessful, otherwise returns archive pointerisArchive(archivePath: string): boolean
- tries to open an archive at specified path. Checks whether an archive is one of the skippable formats (supplied in constructor) - if it is, returnsfalse
. When archive can be opened and is not skippable, returnstrue
.listFiles(archivePath: string): string[]
- returns list of files in an archive. The list is empty if archive cannot be opened (TODO: change the behavior to return an error in such case)async *walk(archivePath: string, outPath: string, keepUnpackedFiles: boolean): AsyncGenerator<ArchiveWalkEntry, Result, void>
- walks through the archive atarchivePath
, descending into archives and directories inside walked archives and extracting contents for handling atoutPath
(in-memory walking is currently not supported, only on-disk walking and access). For each entry (file, directory or archive), the generator returnsArchiveWalkEntry
. IfkeepUnpackedFiles
istrue
, then the generator will not remove entry file immediately after callingnext
on it (it will remain on-disk underoutPath
), otherwise the file will be deleted after callingnext
.async *iterateContents(archivePath: string, outPath: string, keepUnpackedFiles?: boolean): AsyncGenerator<ArchiveContentsEntry, Result, void>
- iterates through the archive atarchivePath
. Very similar mechanism towalk
however, this method does not descend into encountered archives.close(): void
- closeslibarchive
that was opened by the constructor
deno
- tested on 1.17 and uplibarchive.so
- for archives handling
unstable
allow-ffi
The main issue currently is that the lib always consumes disk-space when walking recursively through the archive. While this is not a bad thing for all use-cases, in-memory handling of small archives/files could speed up the process and relieve the disk from taking part in the process. libarchive
seems to have methods that handle in-memory archive operations but those are not used with FFI in this library yet. It's a TODO.