@@ -20,16 +20,7 @@ export interface HttpOptions {
20
20
}
21
21
22
22
export class HttpLocation implements SnapLocation {
23
- // We keep contents separate because then we can use only one Blob in cache,
24
- // which we convert to Uint8Array when actually returning the file.
25
- //
26
- // That avoids deepCloning file contents.
27
- // I imagine ArrayBuffers are copy-on-write optimized, meaning
28
- // in most often case we'll only have one file contents in common case.
29
- private readonly cache = new Map <
30
- string ,
31
- { file : VirtualFile ; contents : Blob }
32
- > ( ) ;
23
+ private readonly cache = new Map < string , VirtualFile > ( ) ;
33
24
34
25
private validatedManifest ?: VirtualFile < SnapManifest > ;
35
26
@@ -80,11 +71,7 @@ export class HttpLocation implements SnapLocation {
80
71
const relativePath = normalizeRelative ( path ) ;
81
72
const cached = this . cache . get ( relativePath ) ;
82
73
if ( cached !== undefined ) {
83
- const { file, contents } = cached ;
84
- const value = new Uint8Array ( await contents . arrayBuffer ( ) ) ;
85
- const vfile = file . clone ( ) ;
86
- vfile . value = value ;
87
- return vfile ;
74
+ return cached . clone ( ) ;
88
75
}
89
76
90
77
const canonicalPath = this . toCanonical ( relativePath ) . toString ( ) ;
@@ -94,17 +81,17 @@ export class HttpLocation implements SnapLocation {
94
81
`Failed to fetch "${ canonicalPath } ". Status code: ${ response . status } .` ,
95
82
) ;
96
83
}
84
+ const buffer = await response . arrayBuffer ( ) ;
97
85
const vfile = new VirtualFile ( {
98
- value : '' ,
86
+ value : new Uint8Array ( buffer ) ,
99
87
path : relativePath ,
100
88
data : { canonicalPath } ,
101
89
} ) ;
102
- const blob = await response . blob ( ) ;
103
90
assert (
104
91
! this . cache . has ( relativePath ) ,
105
92
'Corrupted cache, multiple files with same path.' ,
106
93
) ;
107
- this . cache . set ( relativePath , { file : vfile , contents : blob } ) ;
94
+ this . cache . set ( relativePath , vfile ) ;
108
95
109
96
return this . fetch ( relativePath ) ;
110
97
}
0 commit comments