Пример #1
0
        public jcCCResponseItem DecompressFile(byte[] compressedData)
        {
            var response = new jcCCResponseItem();

            var ms = new MemoryStream(compressedData);

            using (var reader = new BsonDataReader(ms)) {
                var serializer = new JsonSerializer();

                var obj = serializer.Deserialize <jcCCA>(reader);

                response.OutputFile = obj.Filename + ".org";

                response.compressedData = new byte[0];

                var data = new List <byte>();

                foreach (var patternID in obj.Patterns)
                {
                    data.AddRange(obj.Data.FirstOrDefault(a => a.Index == (patternID - 1))?.Data ?? throw new InvalidOperationException());
                }

                response.compressedData = data.ToArray();
            }

            return(response);
        }
Пример #2
0
        public jcCCResponseItem CompressFile(string fileName, byte[] uncompressedData, int numberOfSlices, bool useSlowerMethod = true, bool generateHash = true)
        {
            var response = new jcCCResponseItem {
                OriginalSize = uncompressedData.Length
            };

            if (useSlowerMethod)
            {
                ProcessSlower(uncompressedData, numberOfSlices);
            }
            else
            {
                ProcessFaster(uncompressedData, numberOfSlices);
            }

            response.compressedData     = GetBytes(fileName);
            response.percentCompression = ((double)response.compressedData.Length / uncompressedData.Length);
            response.NewSize            = response.compressedData.Length;

            if (generateHash)
            {
                response.Hash = response.compressedData.ComputeMD5();
            }

            return(response);
        }