1- import { ensureFile } from "./deps.ts" ;
2- import { copy , ensureDir , join , noop , Untar , ZipReader } from "./deps.ts" ;
31import { formatUnzipEntryFileName } from "./format.ts" ;
2+ import {
3+ copy ,
4+ ensureDir ,
5+ ensureFile ,
6+ type Entry ,
7+ join ,
8+ noop ,
9+ pass ,
10+ TarEntry ,
11+ Untar ,
12+ ZipReader ,
13+ } from "./deps.ts" ;
414
515interface UntarOptions {
616 ignore ?: ( entryName : string ) => boolean ;
17+ normalize ?( entry : TarEntry [ ] ) : TarEntry [ ] ;
718}
819
920export async function untar (
@@ -14,7 +25,11 @@ export async function untar(
1425 const reader = await Deno . open ( file , { read : true } ) ;
1526 const untar = new Untar ( reader ) ;
1627 const paths : string [ ] = [ ] ;
17- for await ( const entry of untar ) {
28+ let entrys = await Array . fromAsync ( untar ) ;
29+ if ( options ?. normalize ) {
30+ entrys = options . normalize ( entrys ) ;
31+ }
32+ for ( const entry of entrys ) {
1833 const { fileName, type } = entry ;
1934 if ( options ?. ignore && options ?. ignore ( fileName ) ) {
2035 continue ;
@@ -41,6 +56,8 @@ interface UnzipOptions {
4156 */
4257 useWebWorkers ?: boolean ;
4358 nameEncoding ?: string ;
59+
60+ normalize ?( entry : Entry [ ] ) : Entry [ ] ;
4461}
4562
4663export async function unzip (
@@ -52,9 +69,21 @@ export async function unzip(
5269 const zipReader = new ZipReader ( fd ) ;
5370 const entrys = await zipReader . getEntries ( ) ;
5471 const paths : string [ ] = [ ] ;
55- const { ignore = noop , useWebWorkers = false , nameEncoding } = options || { } ;
56- const promises = entrys . map ( async ( entry ) => {
57- formatUnzipEntryFileName ( entry , nameEncoding ) ;
72+ const {
73+ ignore = noop ,
74+ useWebWorkers = false ,
75+ nameEncoding,
76+ normalize = pass ,
77+ } = options || { } ;
78+
79+ const newEntrys = normalize (
80+ entrys . map ( ( entry ) => {
81+ formatUnzipEntryFileName ( entry , nameEncoding ) ;
82+ return entry ;
83+ } ) ,
84+ ) ;
85+
86+ const promises = newEntrys . map ( async ( entry ) => {
5887 if ( ignore ( entry . filename ) ) {
5988 return ;
6089 }
0 commit comments