@@ -50,7 +50,6 @@ use tracing::{error, info, info_span, instrument, trace, warn};
5050use tracing_futures:: Instrument as _;
5151use walkdir:: WalkDir ;
5252
53- const ZSTD_EOF_BYTES : [ u8 ; 3 ] = [ 0x01 , 0x00 , 0x00 ] ;
5453const ARCHIVE_INDEX_FILE_EXTENSION : & str = "index" ;
5554
5655type FileRange = RangeInclusive < u64 > ;
@@ -876,12 +875,9 @@ impl AsyncStorage {
876875 // download the compressed raw blob first.
877876 // Like this we can first check if it's worth recompressing & re-uploading.
878877 let mut compressed_blob = compressed_stream. materialize ( usize:: MAX ) . await ?;
879- if compressed_blob
880- . content
881- . last_chunk :: < { ZSTD_EOF_BYTES . len ( ) } > ( )
882- == Some ( & ZSTD_EOF_BYTES )
883- {
884- info ! ( path, "Archive already has correct zstd ending, skipping" ) ;
878+
879+ if decompress ( compressed_blob. content . as_slice ( ) , alg, usize:: MAX ) . is_ok ( ) {
880+ info ! ( path, "Archive can be decompressed, skipping" ) ;
885881 continue ;
886882 }
887883
@@ -891,20 +887,14 @@ impl AsyncStorage {
891887 let mut decompressed = Vec :: new ( ) ;
892888 {
893889 // old async-compression can read the broken zstd stream
894- let mut reader = wrap_reader_for_decompression (
895- io:: Cursor :: new ( compressed_blob. content . clone ( ) ) ,
896- alg,
897- ) ;
890+ let mut reader =
891+ wrap_reader_for_decompression ( compressed_blob. content . as_slice ( ) , alg) ;
898892
899893 tokio:: io:: copy ( & mut reader, & mut decompressed) . await ?;
900894 }
901895
902896 let mut buf = Vec :: with_capacity ( decompressed. len ( ) ) ;
903- compress_async ( & mut io:: Cursor :: new ( & decompressed) , & mut buf, alg) . await ?;
904- debug_assert_eq ! (
905- buf. last_chunk:: <{ ZSTD_EOF_BYTES . len( ) } >( ) ,
906- Some ( & ZSTD_EOF_BYTES )
907- ) ;
897+ compress_async ( decompressed. as_slice ( ) , & mut buf, alg) . await ?;
908898 compressed_blob. content = buf;
909899 compressed_blob. compression = Some ( alg) ;
910900
@@ -1176,12 +1166,13 @@ pub(crate) fn source_archive_path(name: &str, version: &Version) -> String {
11761166
11771167#[ cfg( test) ]
11781168mod test {
1179- use crate :: test:: { TestEnvironment , V0_1 } ;
1180-
11811169 use super :: * ;
1170+ use crate :: test:: { TestEnvironment , V0_1 } ;
11821171 use std:: env;
11831172 use test_case:: test_case;
11841173
1174+ const ZSTD_EOF_BYTES : [ u8 ; 3 ] = [ 0x01 , 0x00 , 0x00 ] ;
1175+
11851176 fn streaming_blob (
11861177 content : impl Into < Vec < u8 > > ,
11871178 alg : Option < CompressionAlgorithm > ,
0 commit comments