@@ -187,10 +187,15 @@ public async Task UploadAssetChunkedAsync(
187187 /// </summary>
188188 /// <param name="key">The key of the asset to download.</param>
189189 /// <param name="maxConcurrency">The maximum number of concurrent chunk downloads.</param>
190+ /// <param name="acceptEncodings">The encodings to accept for the asset in order. Defaults to ["gzip", "deflate", "br", "identity"]</param>
190191 /// <returns>The downloaded asset content as a byte array.</returns>
191- public async Task < byte [ ] > DownloadAssetAsync ( string key , int maxConcurrency = 10 )
192+ public async Task < ( byte [ ] Asset , string ContentEncoding ) > DownloadAssetAsync (
193+ string key ,
194+ int maxConcurrency = 10 ,
195+ List < string > ? acceptEncodings = null
196+ )
192197 {
193- List < string > acceptEncodings = new ( ) { "identity " , "gzip " , "deflate " , "br " } ;
198+ acceptEncodings ?? = new ( ) { "gzip " , "deflate " , "br " , "identity " } ;
194199 GetResult result = await this . GetAsync ( key , acceptEncodings ) ;
195200
196201 if ( ! result . TotalLength . TryToUInt64 ( out ulong totalLength ) )
@@ -199,12 +204,12 @@ public async Task<byte[]> DownloadAssetAsync(string key, int maxConcurrency = 10
199204 }
200205 if ( totalLength == ( ulong ) result . Content . Length )
201206 {
202- return result . Content ;
207+ return ( result . Content , result . ContentEncoding ) ;
203208 }
204209 int chunkCount = ( int ) Math . Ceiling ( ( double ) totalLength / result . Content . Length ) ;
205210
206211 // Create a list to store the chunk tasks
207- List < Task < byte [ ] > > chunkTasks = new List < Task < byte [ ] > > ( ) ;
212+ List < Task < byte [ ] > > chunkTasks = new ( ) ;
208213
209214 // Create a semaphore to limit the number of concurrent tasks
210215 SemaphoreSlim semaphore = new ( maxConcurrency ) ;
@@ -236,44 +241,7 @@ public async Task<byte[]> DownloadAssetAsync(string key, int maxConcurrency = 10
236241 // Combine all the bytes into one byte[]
237242 byte [ ] combinedBytes = result . Content . Concat ( chunkTasks . SelectMany ( t => t . Result ) ) . ToArray ( ) ;
238243
239- switch ( result . ContentEncoding )
240- {
241- case "identity" :
242- case null :
243- case "" :
244- break ;
245- case "gzip" :
246- using ( var memoryStream = new MemoryStream ( combinedBytes ) )
247- using ( var gzipStream = new GZipStream ( memoryStream , CompressionMode . Decompress ) )
248- using ( var decompressedStream = new MemoryStream ( ) )
249- {
250- gzipStream . CopyTo ( decompressedStream ) ;
251- combinedBytes = decompressedStream . ToArray ( ) ;
252- }
253- break ;
254- case "deflate" :
255- using ( var memoryStream = new MemoryStream ( combinedBytes ) )
256- using ( var deflateStream = new DeflateStream ( memoryStream , CompressionMode . Decompress ) )
257- using ( var decompressedStream = new MemoryStream ( ) )
258- {
259- deflateStream . CopyTo ( decompressedStream ) ;
260- combinedBytes = decompressedStream . ToArray ( ) ;
261- }
262- break ;
263- case "br" :
264- using ( var memoryStream = new MemoryStream ( combinedBytes ) )
265- using ( var brotliStream = new BrotliStream ( memoryStream , CompressionMode . Decompress ) )
266- using ( var decompressedStream = new MemoryStream ( ) )
267- {
268- brotliStream . CopyTo ( decompressedStream ) ;
269- combinedBytes = decompressedStream . ToArray ( ) ;
270- }
271- break ;
272- default :
273- throw new NotImplementedException ( $ "Content encoding { result . ContentEncoding } is not supported") ;
274- }
275-
276- return combinedBytes ;
244+ return ( combinedBytes , result . ContentEncoding ) ;
277245 }
278246
279247 /// <summary>
0 commit comments