@@ -149,28 +149,41 @@ private static int ProcessCompress(CommandLineParser<BlazerCommandLineOptions> o
149149 }
150150 else throw new InvalidOperationException ( "Invalid compression mode" ) ;
151151
152- if ( opt . BlobOnly )
152+ if ( ! string . IsNullOrEmpty ( opt . MaxBlockSize ) )
153153 {
154- compressionOptions . IncludeCrc = false ;
155- compressionOptions . IncludeFooter = false ;
156- compressionOptions . IncludeHeader = false ;
157- compressionOptions . MaxBlockSize = 1 << 24 ;
158- compressionOptions . FileInfo = null ;
154+ if ( opt . MaxBlockSize . All ( char . IsDigit ) ) compressionOptions . MaxBlockSize = Convert . ToInt32 ( opt . MaxBlockSize ) ;
155+ else
156+ {
157+ BlazerFlags flagsBlockSize ;
158+ if ( Enum . TryParse ( "InBlockSize" + opt . MaxBlockSize , true , out flagsBlockSize ) )
159+ compressionOptions . SetMaxBlockSizeFromFlags ( flagsBlockSize ) ;
160+ }
159161 }
160162
161163 if ( truncateOutFile )
162164 new FileStream ( archiveName , FileMode . Truncate , FileAccess . Write ) . Close ( ) ;
163165
164166 var outStream = opt . Stdout ? Console . OpenStandardOutput ( ) : new FileStream ( archiveName , FileMode . OpenOrCreate , FileAccess . Write , FileShare . Read ) ;
165167
166- Stream blazerStream = new BlazerInputStream ( outStream , compressionOptions ) ;
168+ Stream blazerStream = opt . DataArray ? ( Stream ) new MemoryStream ( ) : new BlazerInputStream ( outStream , compressionOptions ) ;
167169
168170 using ( var inFile = new StatStream ( opt . Stdin ? Console . OpenStandardInput ( ) : File . OpenRead ( fileName ) , ! opt . Stdout ) )
169171 using ( var outFile = blazerStream )
170172 {
171173 inFile . CopyTo ( outFile ) ;
172174 }
173175
176+ if ( opt . DataArray )
177+ {
178+ var sourceData = ( blazerStream as MemoryStream ) . ToArray ( ) ;
179+ var encoder = compressionOptions . Encoder ;
180+ encoder . Init ( sourceData . Length ) ;
181+ var res = encoder . Encode ( sourceData , 0 , sourceData . Length ) ;
182+ outStream . Write ( new [ ] { ( byte ) sourceData . Length , ( byte ) ( sourceData . Length >> 8 ) , ( byte ) ( sourceData . Length >> 16 ) , ( byte ) ( sourceData . Length >> 24 ) } , 0 , 4 ) ;
183+ outStream . Write ( res . Buffer , res . Offset , res . Count ) ;
184+ outStream . Close ( ) ;
185+ }
186+
174187 return 0 ;
175188 }
176189
@@ -212,34 +225,39 @@ private static int ProcessDecompress(CommandLineParser<BlazerCommandLineOptions>
212225
213226 var decOptions = new BlazerDecompressionOptions ( opt . Password ) { EncyptFull = opt . EncryptFull } ;
214227
215- if ( opt . BlobOnly )
216- {
217- decOptions . CompressionOptions = new BlazerCompressionOptions
218- {
219- IncludeCrc = false ,
220- IncludeFooter = false ,
221- IncludeHeader = false ,
222- FileInfo = null ,
223- MaxBlockSize = 1 << 24
224- } ;
228+ BlazerOutputStream outBlazerStream = null ;
229+ Stream outStream = null ;
225230
231+ if ( opt . DataArray )
232+ {
226233 var mode = ( opt . Mode ?? "block" ) . ToLowerInvariant ( ) ;
227234 if ( mode == "stream" || mode == "streamhigh" ) decOptions . SetDecoderByAlgorithm ( BlazerAlgorithm . Stream ) ;
228235 else if ( mode == "none" ) decOptions . SetDecoderByAlgorithm ( BlazerAlgorithm . NoCompress ) ;
229236 else if ( mode == "block" ) decOptions . SetDecoderByAlgorithm ( BlazerAlgorithm . Block ) ;
230237 else throw new InvalidOperationException ( "Unsupported mode" ) ;
238+ var ms = new MemoryStream ( ) ;
239+ inStreamSource . CopyTo ( ms ) ;
240+ var comprArray = ms . ToArray ( ) ;
241+ var uncomprLength = comprArray [ 0 ] | ( comprArray [ 1 ] << 8 ) | ( comprArray [ 2 ] << 16 ) | ( comprArray [ 3 ] << 24 ) ;
242+ var decoder = decOptions . Decoder ;
243+ decoder . Init ( uncomprLength ) ;
244+ var decoded = decoder . Decode ( comprArray , 4 , comprArray . Length , true ) ;
245+ outStream = new MemoryStream ( decoded . Buffer , decoded . Offset , decoded . Count ) ;
246+ }
247+ else
248+ {
249+ outBlazerStream = new BlazerOutputStream ( inStreamSource , decOptions ) ;
250+ outStream = outBlazerStream ;
231251 }
232-
233- var outStream = new BlazerOutputStream ( inStreamSource , decOptions ) ;
234252
235253 var fileName = archiveName ;
236254 var applyFileInfoAfterComplete = false ;
237255 if ( archiveName . EndsWith ( ".blz" ) ) fileName = fileName . Substring ( 0 , fileName . Length - 4 ) ;
238256 else fileName += ".unpacked" ;
239257
240- if ( outStream . FileInfo != null && ! opt . NoFileName )
258+ if ( outBlazerStream != null && outBlazerStream . FileInfo != null && ! opt . NoFileName )
241259 {
242- fileName = outStream . FileInfo . FileName ;
260+ fileName = outBlazerStream . FileInfo . FileName ;
243261 applyFileInfoAfterComplete = true ;
244262 }
245263
@@ -263,7 +281,7 @@ private static int ProcessDecompress(CommandLineParser<BlazerCommandLineOptions>
263281 inFile . CopyTo ( outFile ) ;
264282 }
265283
266- if ( applyFileInfoAfterComplete ) outStream . FileInfo . ApplyToFile ( ) ;
284+ if ( applyFileInfoAfterComplete ) outBlazerStream . FileInfo . ApplyToFile ( ) ;
267285
268286 return 0 ;
269287 }
@@ -291,25 +309,29 @@ private static int ProcessTest(CommandLineParser<BlazerCommandLineOptions> optio
291309
292310 var decOptions = new BlazerDecompressionOptions ( opt . Password ) { EncyptFull = opt . EncryptFull } ;
293311
294- if ( opt . BlobOnly )
295- {
296- decOptions . CompressionOptions = new BlazerCompressionOptions
297- {
298- IncludeCrc = false ,
299- IncludeFooter = false ,
300- IncludeHeader = false ,
301- FileInfo = null ,
302- MaxBlockSize = 1 << 24
303- } ;
312+ Stream outStream ;
304313
314+ if ( opt . DataArray )
315+ {
305316 var mode = ( opt . Mode ?? "block" ) . ToLowerInvariant ( ) ;
306317 if ( mode == "stream" || mode == "streamhigh" ) decOptions . SetDecoderByAlgorithm ( BlazerAlgorithm . Stream ) ;
307318 else if ( mode == "none" ) decOptions . SetDecoderByAlgorithm ( BlazerAlgorithm . NoCompress ) ;
308319 else if ( mode == "block" ) decOptions . SetDecoderByAlgorithm ( BlazerAlgorithm . Block ) ;
309320 else throw new InvalidOperationException ( "Unsupported mode" ) ;
321+ var ms = new MemoryStream ( ) ;
322+ inStreamSource . CopyTo ( ms ) ;
323+ var comprArray = ms . ToArray ( ) ;
324+ var uncomprLength = comprArray [ 0 ] | ( comprArray [ 1 ] << 8 ) | ( comprArray [ 2 ] << 16 ) | ( comprArray [ 3 ] << 24 ) ;
325+ var decoder = decOptions . Decoder ;
326+ decoder . Init ( uncomprLength ) ;
327+ // if we do not fail - all ok
328+ var decoded = decoder . Decode ( comprArray , 4 , comprArray . Length , true ) ;
329+ outStream = new MemoryStream ( decoded . Buffer , decoded . Offset , decoded . Count ) ;
330+ }
331+ else
332+ {
333+ outStream = new BlazerOutputStream ( inStreamSource , decOptions ) ;
310334 }
311-
312- var outStream = new BlazerOutputStream ( inStreamSource , decOptions ) ;
313335
314336 using ( var inFile = outStream )
315337 using ( var outFile = new StatStream ( new NullStream ( ) , true ) )
@@ -346,22 +368,10 @@ private static int ProcessList(CommandLineParser<BlazerCommandLineOptions> optio
346368
347369 var decOptions = new BlazerDecompressionOptions ( opt . Password ) { EncyptFull = opt . EncryptFull } ;
348370
349- if ( opt . BlobOnly )
371+ if ( opt . DataArray )
350372 {
351- decOptions . CompressionOptions = new BlazerCompressionOptions
352- {
353- IncludeCrc = false ,
354- IncludeFooter = false ,
355- IncludeHeader = false ,
356- FileInfo = null ,
357- MaxBlockSize = 1 << 24
358- } ;
359-
360- var mode = ( opt . Mode ?? "block" ) . ToLowerInvariant ( ) ;
361- if ( mode == "stream" || mode == "streamhigh" ) decOptions . SetDecoderByAlgorithm ( BlazerAlgorithm . Stream ) ;
362- else if ( mode == "none" ) decOptions . SetDecoderByAlgorithm ( BlazerAlgorithm . NoCompress ) ;
363- else if ( mode == "block" ) decOptions . SetDecoderByAlgorithm ( BlazerAlgorithm . Block ) ;
364- else throw new InvalidOperationException ( "Unsupported mode" ) ;
373+ Console . WriteLine ( "Data array does not contain file info" ) ;
374+ return 1 ;
365375 }
366376
367377 // format is simplified 7z output
0 commit comments