예제 #1
0
        public UserGet Decompress(byte[] inFile)
        {
            using (var input = new MemoryStream(inFile))
                using (var output = new MemoryStream())
                {
                    var decoder = new SevenZip.SDK.Compress.LZMA.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 outSize = 0;
                    for (int i = 0; i < 8; i++)
                    {
                        int v = input.ReadByte();
                        if (v < 0)
                        {
                            throw (new Exception("Can't Read 1"));
                        }
                        outSize |= ((long)(byte)v) << (8 * i);
                    }
                    long compressedSize = input.Length - input.Position;

                    decoder.Code(input, output, compressedSize, outSize, null);
                    output.Position = 0;
                    return(Serializer.Deserialize <UserGet>(output));
                }
        }
예제 #2
0
 // This is the decompression function
 private static void Decompress(string[] args)
 {
     // We call the 7zip decoder
     SevenZip.SDK.Compress.LZMA.Decoder decoder = new SevenZip.SDK.Compress.LZMA.Decoder();
     // We get an array of file list ( All files in args[0] folder, where args[2] is the filter
     string[] filePaths = Directory.GetFiles(args[0], args[2]);
     // Directory exist or not, we create the folder
     Directory.CreateDirectory(args[1]);
     // For each files in the specified folder, we decode it
     foreach (string filePath in filePaths)
     {
         // We get the file properties ( Size, date, owner, etc.. )
         FileInfo f = new FileInfo(filePath);
         // We work on the input file
         using (FileStream input = new FileStream(filePath, FileMode.Open))
         {
             // We work on the output file
             using (FileStream output = new FileStream(Path.Combine(args[1], Path.GetFileName(filePath)), FileMode.Create))
             {
                 // Read the decoder properties
                 byte[] properties = new byte[5];
                 // Take the 5 bytes after offset 0
                 input.Read(properties, 0, 5);
                 // Read in the decompress file size.
                 byte[] fileLengthBytes = new byte[4];
                 // Take 4 bytes after offset 0
                 input.Read(fileLengthBytes, 0, 4);
                 // Convert to Int32
                 int fileLength = BitConverter.ToInt32(fileLengthBytes, 0);
                 // Set the decoder parameters
                 decoder.SetDecoderProperties(properties);
                 // Write the decompressed file in output directory
                 decoder.Code(input, output, input.Length, fileLength, null);
                 // Free
                 output.Flush();
                 // Free
                 output.Close();
             }
             // Free
             input.Close();
         }
     }
 }