File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed
turbopack/crates/turbo-tasks-fs/src Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -162,12 +162,28 @@ fn compress_bytes(bytes: Cow<'static, [u8]>) -> RopeElem {
162
162
163
163
match bytes {
164
164
Cow :: Borrowed ( b) => Static ( b) ,
165
- Cow :: Owned ( b) => Compressed ( b. len ( ) as u32 , b) ,
165
+ Cow :: Owned ( b) => {
166
+ let mut encoder = lz4:: EncoderBuilder :: new ( )
167
+ . build ( Vec :: new ( ) )
168
+ . expect ( "lz4 version mismatch" ) ;
169
+
170
+ encoder. write_all ( & b) . expect ( "failed to compress bytes" ) ;
171
+
172
+ let ( output, result) = encoder. finish ( ) ;
173
+ result. expect ( "failed to compress bytes" ) ;
174
+
175
+ Compressed ( output. len ( ) as u32 , output)
176
+ }
166
177
}
167
178
}
168
179
169
180
fn decompress_bytes ( bytes : & [ u8 ] , len : u32 ) -> Cow < [ u8 ] > {
170
- Cow :: Borrowed ( bytes)
181
+ let mut decoder = lz4:: Decoder :: new ( Cursor :: new ( bytes) ) . expect ( "lz4 version mismatch" ) ;
182
+ let mut buf = Vec :: with_capacity ( len as usize ) ;
183
+ decoder. read_to_end ( & mut buf) . unwrap_or_else ( |err| {
184
+ unreachable ! ( "internal error: failed to decompress bytes while we compressed them. {err:?}" )
185
+ } ) ;
186
+ Cow :: Owned ( buf)
171
187
}
172
188
173
189
impl RopeBuilder {
You can’t perform that action at this time.
0 commit comments