Exemplo n.º 1
0
 private void CompressInMemoryAndAddDic(int i, byte[] bytes, EventDictionary <int, byte[]> eventDictionary)
 {
     using (var memoryStream = new MemoryStream(bytes))
         using (var outMemory = new MemoryStream())
         {
             using (var zip = new GZipStream(outMemory, CompressionLevel.Optimal))
                 memoryStream.CopyTo(zip);
             eventDictionary.Add(i, outMemory.ToArray());
         }
 }
Exemplo n.º 2
0
 public void Compress([NotNull] string filePath, string savepath = null)
 {
     savepath = savepath ?? filePath + Extention;
     using (var threadQueue = new TaskManager())
         using (var outFileWriter = new OutFileWriter(new FileStream(savepath, FileMode.Create, FileAccess.Write)))
         {
             var dic = new EventDictionary <int, byte[]>();
             dic.OnDictionaryChanged += outFileWriter.WriteDataInFile;
             using (var batchFileReader = new BatchFileReader(filePath))
             {
                 var i     = 0;
                 var bytes = batchFileReader.ReadNext();
                 while (bytes.Any())
                 {
                     var currentBytes = bytes;
                     var currentPart  = i;
                     threadQueue.AddTask(x => { CompressInMemoryAndAddDic(currentPart, currentBytes, dic); }, i);
                     i++;
                     bytes = batchFileReader.ReadNext();
                 }
             }
             threadQueue.JoinAll();
         }
 }