Esempio n. 1
0
        public static string DecompressToString(byte[] bytData)
        {
            byte[] bytDecompressedData = CompressionManager.Decompress(bytData);

            string strData = ASCIIEncoding.ASCII.GetString(bytDecompressedData);

            return(strData);
        }
Esempio n. 2
0
        private void Refresh()
        {
            int intFileDataStartingIndex = 0;

            CompressedFileRecord[] objRecords = new CompressedFileRecord[] { };

            CompressedStream.Position = 0;
            if (CompressedStream.Length > 0)
            {
                if (CompressedStream.Length < CompressedStreamSignature.Length)
                {
                    throw new Exception("The stream does not represent a valid format.");
                }

                byte[] bytBuffer = new byte[CompressedStreamSignature.Length];
                CompressedStream.Read(bytBuffer, 0, bytBuffer.Length);

                for (int intIndex = 0; intIndex < bytBuffer.Length; intIndex++)
                {
                    if (bytBuffer[intIndex] != CompressedStreamSignature[intIndex])
                    {
                        throw new Exception("The stream does not represent a valid format.");
                    }
                }

                bytBuffer = new byte[4];
                CompressedStream.Read(bytBuffer, 0, 4);

                int intRecordLength = BitConverter.ToInt32(bytBuffer, 0);
                bytBuffer = new byte[intRecordLength];

                CompressedStream.Read(bytBuffer, 0, intRecordLength);
                intFileDataStartingIndex = (int)CompressedStream.Position;

                byte[] bytRecordBytes = CompressionManager.Decompress(bytBuffer);
                string strRecordData  = ASCIIEncoding.ASCII.GetString(bytRecordBytes);

                objRecords = CompressedFileRecordManager.FromString(strRecordData);
            }

            CompressedFileRecordManager = new CompressedFileRecordManager(intFileDataStartingIndex, objRecords, CompressedFileRecordState.Updated);
        }
Esempio n. 3
0
        private void ExtractFile(CompressedFileRecord objRecord, CompressedFileRecordState enuRecordState, Stream objTargetStream)
        {
            if (enuRecordState == CompressedFileRecordState.Inserted)
            {
                using (FileStream objDiskFileStream = new FileStream(objRecord.OriginalFilePath, FileMode.Open, FileAccess.Read))
                {
                    CompressionManager.CopyToStream(objDiskFileStream, objTargetStream);
                }
            }
            else
            {
                int intFileStartIndex = CompressedFileRecordManager.FindFileStartIndex(objRecord);
                if (intFileStartIndex == -1)
                {
                    throw new FileNotFoundException("Unable to locate '" + objRecord.RelativeFilePath + "' within package.");
                }

                CompressedStream.Position = intFileStartIndex;
                CompressionManager.Decompress(CompressedStream, objTargetStream, objRecord.Size);
            }
        }