Example #1
0
 public LzEntryOutputStream(Stream stream, Lz4PackageEntry entry, int bufferSize = 0x100000, Lz4Mode mode = 0)
 {
     _baseStream = stream;
     _lz = new Lz4CompressStream(stream, bufferSize, mode);
     try
     {
         _pos = stream.Position;
     }
     catch (Exception)
     {
         _pos = -1L;
     }
     _entry = entry;
     _entry.CompressedSize = 0L;
     _entry.OriginSize = 0L;
     _entry.Entry = stream.Position;
 }
Example #2
0
 public Lz4PackageEntry AddEntry(string name, string originFile, Lz4Mode mode = 0, int blockSize = 0x100000)
 {
     FileStream stream = new FileStream(originFile, FileMode.Open, FileAccess.Read, FileShare.Read, blockSize);
     FileInfo info = new FileInfo(originFile);
     Lz4PackageEntry entry = new Lz4PackageEntry
     {
         Filename = name,
         Package = this,
         EntryCreateTime = DateTime.Now.ToString("o"),
         OriginSize = info.Length,
         CreateTime = info.CreationTime.ToString("o"),
         LastModifyTime = info.LastWriteTime.ToString("o")
     };
     AddEntry(stream, mode, blockSize, entry);
     if (_entries != null)
     {
         _entries.Add(entry);
     }
     if (_map != null)
     {
         _map[entry.Filename] = entry;
     }
     Save(entry);
     return entry;
 }
Example #3
0
 private void AddEntry(Stream stream, Lz4Mode mode, int blockSize, Lz4PackageEntry entry)
 {
     using (FileStream stream2 = OpenWrite(blockSize))
     {
         entry.Entry = stream2.Position;
         using (Lz4CompressionStream stream3 = new Lz4CompressionStream(stream2, blockSize, mode))
         {
             int num;
             byte[] buffer = new byte[blockSize];
             while ((num = stream.Read(buffer, 0, buffer.Length)) > 0)
             {
                 entry.OriginSize += num;
                 stream3.Write(buffer, 0, num);
             }
         }
         entry.CompressedSize = stream2.Position - entry.Entry;
     }
 }
Example #4
0
 internal void Save(Lz4PackageEntry entry)
 {
     DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Lz4PackageEntry));
     using (FileStream stream = new FileStream(InfoFile, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None))
     {
         stream.Seek(0L, SeekOrigin.End);
         serializer.WriteObject(stream, entry);
         stream.WriteByte(13);
         stream.WriteByte(10);
     }
 }
Example #5
0
 public Lz4PackageEntry AddEntry(string name, Stream stream, DateTime createTime, DateTime lastModify, Lz4Mode mode = 0, int blockSize = 0x100000)
 {
     Lz4PackageEntry entry = new Lz4PackageEntry
     {
         Filename = name,
         Package = this,
         EntryCreateTime = DateTime.Now.ToString("o"),
         CreateTime = createTime.ToString("o"),
         LastModifyTime = lastModify.ToString("o")
     };
     AddEntry(stream, mode, blockSize, entry);
     if (_entries != null)
     {
         _entries.Add(entry);
     }
     if (_map != null)
     {
         _map[entry.Filename] = entry;
     }
     Save(entry);
     return entry;
 }
Example #6
0
 public Stream AddEntry(string name, DateTime createTime, DateTime lastModify, Lz4Mode mode, int blockSize)
 {
     Lz4PackageEntry item = new Lz4PackageEntry
     {
         Filename = name,
         Package = this,
         EntryCreateTime = DateTime.Now.ToString("o"),
         CreateTime = createTime.ToString("o"),
         LastModifyTime = lastModify.ToString("o")
     };
     if (_entries != null)
     {
         _entries.Add(item);
     }
     if (_map != null)
     {
         _map[item.Filename] = item;
     }
     FileStream stream = OpenWrite(blockSize);
     item.Entry = stream.Position;
     return new LzEntryOutputStream(stream, item, blockSize, mode);
 }