public static void Unzip(Stream inStream, Stream outStream) { byte[] array = new byte[5]; if (inStream.Read(array, 0, 5) != 5) { throw new Exception("input .lzma is too short"); } Decoder decoder = new Decoder(); decoder.SetDecoderProperties(array); long num = 0L; for (int i = 0; i < 8; i++) { int num2 = inStream.ReadByte(); if (num2 < 0) { throw new Exception("Can't Read 1"); } num |= (long)((byte)num2) << 8 * i; } long inSize = inStream.Length - inStream.Position; decoder.Code(inStream, outStream, inSize, num, null); }
public static Bitmap DecompressFileLZMA(string file) { using MemoryStream spriteBuffer = new MemoryStream(); Decoder decoder = new Decoder(); using BinaryReader reader = new BinaryReader(File.OpenRead(file)); /* * CIP's header, 32 bytes * * Padded with a variable number of NULL bytes (depending on LZMA file size) at the start then the constant * byte sequence of "70 0A FA 80 24" followed by the LZMA file size encoded as a 7-bit integer */ // Since there may be a variable number of NULL bytes just loop until we get through them all, then skip past // the remaining 4 bytes of the constant (really should check their values for file validity but just assume it is) while (reader.ReadByte() == 0) { } reader.ReadUInt32(); while ((reader.ReadByte() & 0x80) == 0x80) { } // LZMA size, 7-bit integer where MSB = flag for next byte used decoder.SetDecoderProperties(reader.ReadBytes(5)); reader.ReadUInt64(); // Should be the decompressed size but CIP writes the compressed sized, so just use a large buffer size // Disabled arithmetic underflow/overflow check in debug mode so this won't cause an exception spriteBuffer.Position = 0; decoder.Code(reader.BaseStream, spriteBuffer, reader.BaseStream.Length - reader.BaseStream.Position, -1, null); spriteBuffer.Position = 0; decoder = null; return(new Bitmap(spriteBuffer)); }
/// <inheritdoc/> protected override void BaseDecompress(Stream inputStream, Stream outputStream) { using (MemoryStream inputMemory = new MemoryStream()) { inputStream.CopyTo(inputMemory); inputStream.Flush(); inputMemory.Flush(); inputMemory.Position = 0; var decoder = new Decoder(); // Read the decoder properties var properties = new byte[5]; inputMemory.Read(properties, 0, 5); decoder.SetDecoderProperties(properties); // Read in the decompress file size. var fileLengthBytes = new byte[8]; inputMemory.Read(fileLengthBytes, 0, 8); var fileLength = BitConverter.ToInt64(fileLengthBytes, 0); // Decode decoder.Code(inputMemory, outputStream, inputMemory.Length, fileLength, null); outputStream.Flush(); } }
/// <summary> /// Decompress engine's LZMA stream. Return new decompressed MemoryStream /// BaseStream don't contains 'decompress size' /// </summary> /// <param name="baseStream">LZMA compressed stream</param> /// <param name="compressSize">Compressed data length</param> /// <param name="decompressedStream">Stream for decompressed output</param> /// <param name="decompreesSize">Decompressed data length</param> /// <returns>Decompressed MemoryStream</returns> public static void DecompressLZMAStream(Stream baseStream, long compressSize, Stream decompressedStream, long decompreesSize) { long basePosition = baseStream.Position; byte[] properties = new byte[PropertiesSize]; int read = baseStream.Read(properties, 0, PropertiesSize); if (read != PropertiesSize) { throw new Exception("Unable to read lzma properties"); } Decoder decoder = new Decoder(); decoder.SetDecoderProperties(properties); long headSize = baseStream.Position - basePosition; long headlessSize = compressSize - headSize; long startPosition = decompressedStream.Position; decoder.Code(baseStream, decompressedStream, headlessSize, decompreesSize, null); if (baseStream.Position > basePosition + compressSize) { throw new Exception($"Read {baseStream.Position - basePosition} more than expected {compressSize}"); } baseStream.Position = basePosition + compressSize; decompressedStream.Position = startPosition; }
public static void Decompress(Stream input, Stream output, Action <long, long> onProgress = null) { var decoder = new Decoder(); byte[] properties = new byte[5]; if (input.Read(properties, 0, 5) != 5) { throw new Exception("input .lzma is too short"); } decoder.SetDecoderProperties(properties); long fileLength = 0; for (int i = 0; i < 8; i++) { int v = input.ReadByte(); if (v < 0) { throw new Exception("Can't Read 1"); } fileLength |= ((long)(byte)v) << (8 * i); } ICodeProgress prg = null; if (onProgress != null) { prg = new DelegateCodeProgress(onProgress); } long compressedSize = input.Length - input.Position; decoder.Code(input, output, compressedSize, fileLength, prg); }
private static byte[] Decompress(byte[] inputBytes) { MemoryStream newInStream = new MemoryStream(inputBytes); Decoder decoder = new Decoder(); newInStream.Seek(0, 0); MemoryStream newOutStream = new MemoryStream(); byte[] properties2 = new byte[5]; if (newInStream.Read(properties2, 0, 5) != 5) { throw (new Exception("input .lzma is too short")); } long outSize = 0; for (int i = 0; i < 8; i++) { int v = newInStream.ReadByte(); if (v < 0) { throw (new Exception("Can't Read 1")); } outSize |= ((long)(byte)v) << (8 * i); } decoder.SetDecoderProperties(properties2); long compressedSize = newInStream.Length - newInStream.Position; decoder.Code(newInStream, newOutStream, compressedSize, outSize, null); byte[] b = newOutStream.ToArray(); return(b); }
private static byte[] DecodeLzma(byte[] lzmaByteArray) { byte[] result = null; Decoder decoder = new Decoder(); using (MemoryStream memoryStream = new MemoryStream(lzmaByteArray)) { memoryStream.Seek(0L, SeekOrigin.Begin); using (MemoryStream memoryStream2 = new MemoryStream()) { byte[] array = new byte[5]; if (memoryStream.Read(array, 0, 5) != 5) { throw new Exception("input .lzma is too short"); } long num = 0L; for (int i = 0; i < 8; i++) { int num2 = memoryStream.ReadByte(); if (num2 < 0) { throw new Exception("Can't Read 1"); } num |= (long)((long)((ulong)((byte)num2)) << 8 * i); } decoder.SetDecoderProperties(array); long inSize = memoryStream.Length - memoryStream.Position; decoder.Code(memoryStream, memoryStream2, inSize, num, null); result = memoryStream2.ToArray(); } } return(result); }
public bool Decrypt(Stream inStream, Stream outStream, bool removeJunk = false, int junkSize = 4) { if (removeJunk) { inStream.Seek((long)junkSize, SeekOrigin.Begin); } byte[] numArray = new byte[5]; if (inStream.Read(numArray, 0, 5) != 5) { return(false); } Decoder decoder = new Decoder(); decoder.SetDecoderProperties(numArray); long outSize = 0L; for (int index = 0; index < 8; ++index) { int num = inStream.ReadByte(); if (num < 0) { return(false); } outSize |= (long)(byte)num << 8 * index; } long inSize = inStream.Length - inStream.Position; decoder.Code(inStream, outStream, inSize, outSize, (ICodeProgress)null); return(true); }
public static void ExpandNatives() { Decoder decoder = new Decoder(); MemoryStream output = new MemoryStream(); using (Stream input = File.Open(Path.Combine(DotMinecraft, "bin/" + GetNativeArchiveFile()), FileMode.Open)) { Decoder coder = new Decoder(); byte[] properties = new byte[5]; input.Read(properties, 0, 5); // Read in the decompress file size. byte[] fileLengthBytes = new byte[8]; input.Read(fileLengthBytes, 0, 8); long fileLength = BitConverter.ToInt64(fileLengthBytes, 0); coder.SetDecoderProperties(properties); coder.Code(input, output, input.Length, fileLength, null); } output.Seek(0, SeekOrigin.Begin); FastZip fastZip = new FastZip(); fastZip.ExtractZip(output, Path.Combine(DotMinecraft, "bin/natives"), FastZip.Overwrite.Always, null, "", "", false, false); File.Delete(Path.Combine(DotMinecraft, "bin/" + GetNativeArchiveFile())); }
public static byte[] Decompress(byte[] inputBytes) { var memoryStream1 = new MemoryStream(inputBytes); var decoder = new Decoder(); memoryStream1.Seek(0L, SeekOrigin.Begin); var memoryStream2 = new MemoryStream(); var numArray = new byte[5]; if (memoryStream1.Read(numArray, 0, 5) != 5) { throw new Exception("input .lzma is too short"); } var outSize = 0L; for (var index = 0; index < 8; ++index) { var num = memoryStream1.ReadByte(); if (num < 0) { throw new Exception("Can't Read 1"); } outSize |= (long)(byte)num << 8 * index; } decoder.SetDecoderProperties(numArray); var inSize = memoryStream1.Length - memoryStream1.Position; decoder.Code(memoryStream1, memoryStream2, inSize, outSize, null); return(memoryStream2.ToArray()); }
public static MemoryStream Decompress(Stream inStream, int lengthPadding = 0) { var decoder = new Decoder(); var newOutStream = new MemoryStream(); var properties2 = new byte[5]; if (inStream.Read(properties2, 0, 5) != 5) { throw new Exception("input .lzma is too short"); } long outSize = 0; for (var i = 0; i < 8; i++) { var v = inStream.ReadByte(); if (v < 0) { throw new Exception("Can't Read 1"); } outSize |= (long)(byte)v << (8 * i); } decoder.SetDecoderProperties(properties2); var compressedSize = inStream.Length - inStream.Position - lengthPadding; decoder.Code(inStream, newOutStream, compressedSize, outSize, null); return(newOutStream); }
/// <summary> /// Decompresses the specified bytes using LZMA and the /// <see cref="CompressionSettings"/> that have been used to originally compress the bytes. /// </summary> /// <param name="compressedBytes">The compressed <c>byte[]</c> array that you want to decompress.</param> /// <param name="compressionSettings">The <see cref="CompressionSettings"/> that have been used to compress the bytes.</param> /// <returns>The decompressed <c>bytes[]</c>.</returns> public byte[] Decompress(byte[] compressedBytes, CompressionSettings compressionSettings) { if (ReferenceEquals(compressedBytes, null)) { return(null); } if (compressedBytes.Length == 0) { return(Array.Empty <byte>()); } byte[] decompressedBytes; var decoder = new Decoder(); MemoryStream input = new MemoryStream(compressedBytes); MemoryStream output = new MemoryStream(compressedBytes.Length / 2 * 3); try { input.Seek(0, 0); byte[] props = new byte[5]; if (input.Read(props, 0, 5) != 5) { throw new InvalidDataException($"{nameof(LzmaUtility)}: input LZMA data is too short. Returning null..."); } long outSize = 0; for (int i = 0; i < 8; i++) { int v = input.ReadByte(); if (v < 0) { throw new InvalidDataException($"{nameof(LzmaUtility)}: Can't read byte at {nameof(input)} position \"{input.Position}\"..."); } outSize |= ((long)(byte)v) << (8 * i); } decoder.SetDecoderProperties(props); long compressedSize = input.Length - input.Position; decoder.Code(input, output, compressedSize, outSize, null); decompressedBytes = output.ToArray(); } catch (Exception e) { string msg = $"{nameof(LzmaUtility)}: Decompression failed; thrown exception: {e.ToString()}"; throw new InvalidDataException(msg); } finally { input.Dispose(); output.Dispose(); } return(decompressedBytes); }
public static void DecompressFile(FileInfo fi) { try { String outputName = fi.FullName.Substring(0, fi.FullName.Length - COMPRESSED_SUFFIX.Length); using (FileStream inStream = fi.OpenRead()) { using (FileStream outStream = new FileStream(outputName, FileMode.Create, FileAccess.Write)) { Decoder decoder = new Decoder(); BinaryReader reader = new BinaryReader(inStream); long outSize = reader.ReadInt64(); long compressedSize = inStream.Length - inStream.Position; byte[] properties = new byte[5]; if (inStream.Read(properties, 0, 5) != 5) { throw (new Exception("input is too short")); } decoder.SetDecoderProperties(properties); decoder.Code(inStream, outStream, compressedSize, outSize, null); } } } catch (Exception e) { System.Console.WriteLine("Exception DecompressFile: " + e.GetType() + " " + e.Message); throw e; } }
/// <summary> /// Decompress a CSV or SC File /// CSV Compressiontype: Lzma /// SC Compressiontype: Lzmha /// </summary> /// <param name="inStream"></param> /// <param name="type"></param> /// <returns></returns> public byte[] Decompress(Stream inStream, CompressionType type) { var stream = new MemoryStream(); var decoder = new Decoder(); if (type == CompressionType.Lzmha) { inStream.Seek(26, SeekOrigin.Current); } var properties = new byte[5]; if (inStream.Read(properties, 0, 5) < 5) { throw new Exception("Invalid properties."); } var buffer = new byte[4]; inStream.Read(buffer, 0, 4); decoder.SetDecoderProperties(properties); decoder.Code(inStream, stream, inStream.Length, BitConverter.ToInt32(buffer, 0), null); inStream.Flush(); inStream.Close(); return(stream.ToArray()); }
protected override RecordNode DecodeDelegate() { byte[] value = (compressedNode.Values[0] as EsfValueNode <byte[]>).Value; ParentNode parentNode = compressedNode.Children[0]; uint value2 = (parentNode.Values[0] as EsfValueNode <uint>).Value; byte[] value3 = (parentNode.Values[1] as EsfValueNode <byte[]>).Value; Decoder decoder = new Decoder(); decoder.SetDecoderProperties(value3); byte[] array = new byte[value2]; using (MemoryStream inStream = new MemoryStream(value, writable: false)) { using (MemoryStream memoryStream = new MemoryStream(array)) { decoder.Code(inStream, memoryStream, value.Length, value2, null); array = memoryStream.ToArray(); } } AbcaFileCodec abcaFileCodec = new AbcaFileCodec(); EsfNode esfNode = abcaFileCodec.Parse(array); using (BinaryReader reader = new BinaryReader(new MemoryStream(array))) { esfNode = abcaFileCodec.Parse(reader); } return(esfNode as RecordNode); }
public Task <byte[]> Decompress(byte[] data) { using (var sourceStream = new MemoryStream(data)) using (var destStream = new MemoryStream()) { var coder = new Decoder(); // Read the decoder properties var properties = new byte[5]; sourceStream.Read(properties, 0, 5); // Read in the decompressed file size. var fileLengthBytes = new byte[8]; sourceStream.Read(fileLengthBytes, 0, 8); var fileLength = BitConverter.ToInt64(fileLengthBytes, 0); coder.SetDecoderProperties(properties); coder.Code(sourceStream, destStream, sourceStream.Length, fileLength, null); destStream.Flush(); return(Task.FromResult(destStream.ToArray())); } }
private void DoDecompressFileLZMA() { try { MemoryStream input = new MemoryStream(deInBytes); MemoryStream output = new MemoryStream(); byte[] properties = new byte[5]; input.Read(properties, 0, 5); byte[] fileLengthBytes = new byte[8]; input.Read(fileLengthBytes, 0, 8); long fileLength = BitConverter.ToInt64(fileLengthBytes, 0); deCoder = new Decoder(); deCoder.SetDecoderProperties(properties); deCoder.Code(input, output, input.Length, fileLength, null); output.Flush(); deOutBytes = output.ToArray(); output.Close(); input.Close(); } catch (System.Exception ex) { Debug.LogError(ex.Message + "\n" + ex.StackTrace); } decompressBytesLZMAFinish = true; }
public string GetText() { using (MemoryStream memory = new MemoryStream()) { using (Stream input = File.OpenRead(@"Resources\Large.7z")) { Decoder coder = new Decoder(); // Read the decoder properties byte[] properties = new byte[5]; input.Read(properties, 0, 5); // Read in the decompress file size. byte[] fileLengthBytes = new byte[8]; input.Read(fileLengthBytes, 0, 8); long fileLength = BitConverter.ToInt64(fileLengthBytes, 0); coder.SetDecoderProperties(properties); coder.Code(input, memory, input.Length, fileLength, null); memory.Flush(); } memory.Seek(0, SeekOrigin.Begin); using (TextReader reader = new StreamReader(memory)) { return(reader.ReadToEnd()); } } }
bool ReadChunk() { var read = BaseStream.Read(propertyBuffer, 0, propertyBuffer.Length); if (read == 0) { return(false); } long chunkSize = 0; if (read != propertyBuffer.Length || !BaseStream.TryReadInt64(out chunkSize)) { throw CorruptionFound(); } if (bufferStream.Length != chunkSize) { bufferStream.SetLength(chunkSize); } if (chunkSize == 0) { return(false); } bufferStream.Position = 0; decoder.SetDecoderProperties(propertyBuffer); decoder.Code(BaseStream, bufferStream, -1, chunkSize, null); bufferStream.Position = 0; return(true); }
/// <summary> /// Decompresses an LZMA stream. /// </summary> /// <param name="sourceFile">The file containing the LZMA compressed stream.</param> /// <param name="destinationFile">The output file containing the decompressed LZMA stream.</param> public static void Decompress(string sourceFile, string destinationFile) { string destinationDir = Path.GetDirectoryName(destinationFile); if (!Directory.Exists(destinationDir)) { Directory.CreateDirectory(destinationDir); } using (FileStream inFile = new FileStream(sourceFile, FileMode.Open)) using (FileStream outFile = new FileStream(destinationFile, FileMode.Create)) { Decoder decoder = new Decoder(); byte[] properties = new byte[5]; byte[] fileLengthBytes = new byte[8]; inFile.Read(properties, 0, 5); inFile.Read(fileLengthBytes, 0, 8); long fileLength = BitConverter.ToInt64(fileLengthBytes, 0); decoder.SetDecoderProperties(properties); decoder.Code(inFile, outFile, inFile.Length, fileLength, progress: null); } }
/// <summary> /// Decompress engine's LZMA stream. Write decomressed data to decompressedStream. /// BaseStream contains 'decompress size' /// </summary> /// <param name="baseStream">LZMA compressed stream</param> /// <param name="compressSize">Compressed data length</param> /// <param name="decompressedStream">Decompressed out stream</param> public static void DecompressLZMASizeStream(Stream baseStream, long compressSize, Stream decompressedStream) { long basePosition = baseStream.Position; byte[] properties = new byte[PropertiesSize]; baseStream.ReadBuffer(properties, 0, PropertiesSize); byte[] countBuffer = new byte[CountSize]; baseStream.ReadBuffer(countBuffer, 0, CountSize); long decompressedSize = BitConverter.ToInt64(countBuffer, 0); Decoder decoder = new Decoder(); decoder.SetDecoderProperties(properties); long headSize = baseStream.Position - basePosition; long dataSize = compressSize - headSize; long startPosition = decompressedStream.Position; decoder.Code(baseStream, decompressedStream, dataSize, decompressedSize, null); if (baseStream.Position > basePosition + compressSize) { throw new Exception($"Read {baseStream.Position - basePosition} more than expected {compressSize}"); } baseStream.Position = basePosition + compressSize; decompressedStream.Position = startPosition; }
internal static void Decompress(Stream inputStream, Stream outputStream) { var decoder = new Decoder(); byte[] properties = new byte[5]; if (inputStream.Read(properties, 0, 5) != 5) { throw (new Exception("input .lzma is too short")); } decoder.SetDecoderProperties(properties); long outSize = 0; for (int i = 0; i < 8; i++) { int v = inputStream.ReadByte(); if (v < 0) { throw (new Exception("Can't Read 1")); } outSize |= ((long)(byte)v) << (8 * i); } long compressedSize = inputStream.Length - inputStream.Position; decoder.Code(inputStream, outputStream, inputStream.Length, -1, null); }
static bool LAMPjieyasuo(string filein, string outfile) { try { if (!File.Exists(filein)) { return(false); } FileStream insStream = new FileStream(filein, FileMode.Open); FileStream outStream = new FileStream(outfile, FileMode.OpenOrCreate); //duqu properties byte[] properies = new byte[5]; insStream.Read(properies, 0, 5); byte[] filelength = new byte[8]; insStream.Read(filelength, 0, 8); long length = BitConverter.ToInt64(filelength, 0); Decoder decoder = new Decoder(); decoder.SetDecoderProperties(properies); decoder.Code(insStream, outStream, insStream.Length, length, null); outStream.Flush(); outStream.Close(); insStream.Close(); } catch (Exception e) { Console.WriteLine(e); throw; } return(false); }
public static MemoryStream Decompress(Stream inStream) { Decoder decoder = new Decoder(); byte[] properties = new byte[5]; if (inStream.Read(properties, 0, 5) != 5) { throw (new Exception("input .lzma is too short")); } decoder.SetDecoderProperties(properties); long outSize = 0; for (int i = 0; i < 8; i++) { int v = inStream.ReadByte(); if (v < 0) { break; } outSize |= ((long)(byte)v) << (8 * i); } long compressedSize = inStream.Length - inStream.Position; var outStream = new MemoryStream(); decoder.Code(inStream, outStream, compressedSize, outSize, null); outStream.Flush(); outStream.Position = 0; return(outStream); }
private static void DeCompress(object obj) { FileChangeInfo fileChangeInfo = (FileChangeInfo)obj; string inpath = fileChangeInfo.inpath; string outpath = fileChangeInfo.outpath; CodeProgress progress = null; if (fileChangeInfo.progressDelegate != null) { progress = new CodeProgress(fileChangeInfo.progressDelegate); } try { Decoder decoder = new Decoder(); FileStream fileStream = new FileStream(inpath, FileMode.Open); progress.fileSize = fileStream.Length; FileStream fileStream2 = new FileStream(outpath, FileMode.Create); int num = 5; byte[] array = new byte[num]; fileStream.Read(array, 0, array.Length); byte[] array2 = new byte[8]; fileStream.Read(array2, 0, 8); long outSize = BitConverter.ToInt64(array2, 0); decoder.SetDecoderProperties(array); decoder.Code(fileStream, fileStream2, fileStream.Length, outSize, progress); fileStream2.Flush(); fileStream2.Close(); fileStream.Close(); Debug.Log("解压完毕"); } catch (Exception ex) { Debug.Log(ex); } }
public byte[] Decompress(byte[] compressedBytes) { using (var inputStream = new MemoryStream(compressedBytes)) using (var outputStream = new MemoryStream()) { Decoder decoder = new Decoder(); byte[] properties = new byte[5]; if (inputStream.Read(properties, 0, 5) != 5) { throw new Exception(); } decoder.SetDecoderProperties(properties); long outSize = 0; for (int i = 0; i < 8; i++) { int v = inputStream.ReadByte(); outSize |= ((long)(byte)v) << (8 * i); } long compressedSize = inputStream.Length - inputStream.Position; decoder.Code(inputStream, outputStream, compressedSize, outSize, null); outputStream.Flush(); return(outputStream.ToArray()); } }
public static MemoryStream StreamDecompress(MemoryStream inStream) { var decoder = new Decoder(); inStream.Seek(0, SeekOrigin.Begin); var newOutStream = new MemoryStream(); var properties = new byte[5]; if (inStream.Read(properties, 0, 5) != 5) { throw new Exception("input .lzma is too short"); } long outSize = 0; for (var i = 0; i < 8; i++) { var v = inStream.ReadByte(); if (v < 0) { throw new Exception("Can't Read 1"); } outSize |= ((long)(byte)v) << (8 * i); } decoder.SetDecoderProperties(properties); var compressedSize = inStream.Length - inStream.Position; decoder.Code(inStream, newOutStream, compressedSize, outSize, null); newOutStream.Position = 0; return(newOutStream); }
/// <summary> /// 使用LZMA算法解压文件 /// </summary> static bool DecompressFileLZMA(string inFile, string outFile) { try { if (!File.Exists(inFile)) { return(false); } FileStream input = new FileStream(inFile, FileMode.Open); FileStream output = new FileStream(outFile, FileMode.OpenOrCreate); byte[] properties = new byte[5]; input.Read(properties, 0, 5); byte[] fileLengthBytes = new byte[8]; input.Read(fileLengthBytes, 0, 8); long fileLength = BitConverter.ToInt64(fileLengthBytes, 0); Decoder coder = new Decoder(); coder.SetDecoderProperties(properties); coder.Code(input, output, input.Length, fileLength, null); output.Flush(); output.Close(); input.Close(); } catch (System.Exception ex) { Debug.LogError(ex.Message); } return(false); }
/// <inheritdoc/> protected override async Task BaseDecompressAsync(Stream inputStream, Stream outputStream, CancellationToken cancellationToken = default) { using (MemoryStream inputMemory = new MemoryStream()) { await inputStream.CopyToAsync(inputMemory, DefaultBufferSize, cancellationToken).ConfigureAwait(false); await inputStream.FlushAsync(cancellationToken).ConfigureAwait(false); await inputMemory.FlushAsync(cancellationToken).ConfigureAwait(false); inputMemory.Position = 0; var decoder = new Decoder(); // Read the decoder properties var properties = new byte[5]; await inputMemory.ReadAsync(properties, 0, 5, cancellationToken).ConfigureAwait(false); decoder.SetDecoderProperties(properties); // Read in the decompress file size. var fileLengthBytes = new byte[8]; await inputMemory.ReadAsync(fileLengthBytes, 0, 8, cancellationToken).ConfigureAwait(false); var fileLength = BitConverter.ToInt64(fileLengthBytes, 0); // Decode decoder.Code(inputMemory, outputStream, inputMemory.Length, fileLength, null); await outputStream.FlushAsync(cancellationToken).ConfigureAwait(false); } }
private void DoDecompressFileLZMA() { try { if (!File.Exists(deInFile)) { decompressFileLZMAFinish = true; return; } FileStream input = new FileStream(deInFile, FileMode.Open); FileStream output = new FileStream(deOutFile, FileMode.OpenOrCreate); byte[] properties = new byte[5]; input.Read(properties, 0, 5); byte[] fileLengthBytes = new byte[8]; input.Read(fileLengthBytes, 0, 8); long fileLength = BitConverter.ToInt64(fileLengthBytes, 0); deCoder = new Decoder(); deCoder.SetDecoderProperties(properties); deCoder.Code(input, output, input.Length, fileLength, null); output.Flush(); output.Close(); input.Close(); } catch (System.Exception ex) { Debug.LogError(ex.Message); } decompressFileLZMAFinish = true; }