@@ -38,22 +38,21 @@ public static SpanOwner<byte> Decompress(string file)
38
38
39
39
public static void Compress ( string file , string output , bool useDictionaries )
40
40
{
41
- using SpanOwner < byte > compressed = Compress ( file , useDictionaries ) ;
41
+ Span < byte > compressed = Compress ( file , useDictionaries ) ;
42
42
using FileStream fs = File . Create ( output ) ;
43
- fs . Write ( compressed . Span ) ;
43
+ fs . Write ( compressed ) ;
44
44
}
45
45
46
- public static SpanOwner < byte > Compress ( string file , bool useDictionaries )
46
+ public static Span < byte > Compress ( string file , bool useDictionaries )
47
47
{
48
48
using FileStream fs = File . OpenRead ( file ) ;
49
49
int size = Convert . ToInt32 ( fs . Length ) ;
50
50
using SpanOwner < byte > buffer = SpanOwner < byte > . Allocate ( size ) ;
51
51
fs . Read ( buffer . Span ) ;
52
52
53
- size = Zstd . GetDecompressedSize ( buffer . Span ) ;
54
- SpanOwner < byte > decompressed = SpanOwner < byte > . Allocate ( size ) ;
55
- Totk . Zstd . Decompress ( buffer . Span , decompressed . Span ) ;
56
- return decompressed ;
53
+ SpanOwner < byte > compressed = SpanOwner < byte > . Allocate ( size ) ;
54
+ size = Totk . Zstd . Compress ( buffer . Span , compressed . Span , file . GetDictioanryId ( useDictionaries ) ) ;
55
+ return compressed . Span [ ..size ] ;
57
56
}
58
57
59
58
public static void DecompressFolder ( string path , string output , bool recursive , Action < int > ? setCount = null , Action < int > ? updateCount = null )
@@ -83,12 +82,12 @@ public static void CompressFolder(string path, string output, bool recursive, Ac
83
82
for ( int i = 0 ; i < files . Length ; i ++ )
84
83
{
85
84
string file = files [ i ] ;
86
- using SpanOwner < byte > data = Compress ( file , useDictionaries ) ;
85
+ Span < byte > compresses = Compress ( file , useDictionaries ) ;
87
86
88
87
string outputFile = Path . Combine ( output , Path . GetRelativePath ( path , $ "{ file } .zs") ) ;
89
88
Directory . CreateDirectory ( Path . GetDirectoryName ( outputFile ) ! ) ;
90
89
using FileStream fs = File . Create ( outputFile ) ;
91
- fs . Write ( data . Span ) ;
90
+ fs . Write ( compresses ) ;
92
91
93
92
updateCount ? . Invoke ( i + 1 ) ;
94
93
}
0 commit comments