@@ -49,7 +49,13 @@ internal Layer(FileInfo backingFile, Descriptor descriptor)
49
49
50
50
public static Layer FromDescriptor ( Descriptor descriptor , ContentStore store )
51
51
{
52
- return new ( new ( store . PathForDescriptor ( descriptor ) ) , descriptor ) ;
52
+ FileInfo path = new ( store . PathForDescriptor ( descriptor ) ) ;
53
+ return FromBackingFile ( path , descriptor ) ;
54
+ }
55
+
56
+ public static Layer FromBackingFile ( FileInfo backingFile , Descriptor descriptor )
57
+ {
58
+ return new ( backingFile , descriptor ) ;
53
59
}
54
60
55
61
public static async Task < Layer > FromFiles ( ( string absPath , string relPath ) [ ] inputFiles , string containerPath , bool isWindowsLayer , string manifestMediaType , ContentStore store , FileInfo layerWritePath , CancellationToken ct )
@@ -219,13 +225,16 @@ private sealed class HashDigestGZipStream : Stream
219
225
private readonly IncrementalHash sha256Hash ;
220
226
private readonly GZipStream compressionStream ;
221
227
222
- public HashDigestGZipStream ( Stream writeStream , bool leaveOpen )
228
+ public HashDigestGZipStream ( Stream writeStream , bool leaveOpen , CompressionMode compressionMode = CompressionMode . Compress )
229
+ : base ( )
223
230
{
224
231
sha256Hash = IncrementalHash . CreateHash ( HashAlgorithmName . SHA256 ) ;
225
- compressionStream = new GZipStream ( writeStream , CompressionMode . Compress , leaveOpen ) ;
232
+ compressionStream = new GZipStream ( writeStream , compressionMode , leaveOpen ) ;
226
233
}
227
234
228
- public override bool CanWrite => true ;
235
+ public override bool CanWrite => compressionStream . CanWrite ;
236
+ public override bool CanRead => compressionStream . CanRead ;
237
+ public override bool CanSeek => compressionStream . CanSeek ;
229
238
230
239
public override void Write ( byte [ ] buffer , int offset , int count )
231
240
{
@@ -271,12 +280,30 @@ public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationTo
271
280
return compressionStream . WriteAsync ( buffer , cancellationToken ) ;
272
281
}
273
282
274
- public override bool CanRead => false ;
275
- public override bool CanSeek => false ;
276
283
public override long Length => throw new NotImplementedException ( ) ;
277
284
public override long Position { get => throw new NotImplementedException ( ) ; set => throw new NotImplementedException ( ) ; }
278
285
279
- public override int Read ( byte [ ] buffer , int offset , int count ) => throw new NotImplementedException ( ) ;
286
+ public override int Read ( byte [ ] buffer , int offset , int count )
287
+ {
288
+ var read = compressionStream . Read ( buffer , offset , count ) ;
289
+ sha256Hash . AppendData ( buffer . AsSpan ( offset , read ) ) ;
290
+ return read ;
291
+ }
292
+
293
+ public override Task < int > ReadAsync ( byte [ ] buffer , int offset , int count , CancellationToken cancellationToken )
294
+ {
295
+ var read = compressionStream . ReadAsync ( buffer , offset , count , cancellationToken ) ;
296
+ sha256Hash . AppendData ( buffer . AsSpan ( offset , read . Result ) ) ;
297
+ return read ;
298
+ }
299
+
300
+ public override ValueTask < int > ReadAsync ( Memory < byte > buffer , CancellationToken cancellationToken = default )
301
+ {
302
+ var read = compressionStream . ReadAsync ( buffer , cancellationToken ) ;
303
+ sha256Hash . AppendData ( buffer . Span . Slice ( 0 , read . Result ) ) ;
304
+ return read ;
305
+ }
306
+
280
307
public override long Seek ( long offset , SeekOrigin origin ) => throw new NotImplementedException ( ) ;
281
308
public override void SetLength ( long value ) => throw new NotImplementedException ( ) ;
282
309
}
0 commit comments