예제 #1
0
        public Lmdb.ChunkDto Compress(byte[] symmetricKey)
        {
            var fileName = _stream.Name + ".lz4";

            _stream.Seek(0, SeekOrigin.Begin);


            using (var chunkFile = File.Create(fileName)) {
                var flags = LZ4StreamFlags.HighCompression | LZ4StreamFlags.IsolateInnerStream;



                using (var aes = new AesCryptoServiceProvider()) {
                    aes.Key     = symmetricKey;
                    aes.Mode    = CipherMode.CBC;
                    aes.Padding = PaddingMode.PKCS7;
                    aes.GenerateIV();
                    var iv = aes.IV;
                    chunkFile.Write(iv, 0, iv.Length);

                    using (var enc = aes.CreateEncryptor())
                        using (var crypto = new CryptoStream(chunkFile, enc, CryptoStreamMode.Write))
                            using (var lz4 = new LZ4Stream(crypto, LZ4StreamMode.Compress, flags, 1048576 * 4)) {
                                Streams.Copy(_stream, lz4, (int)_pos);
                            }
                }
            }

            var size = new FileInfo(fileName).Length;

            return(Lmdb.NewChunkDto()
                   .SetChunkFileName(fileName)
                   .SetUncompressedByteSize(_pos)
                   .SetChunkRecords(_records)
                   .SetCompressedDiskSize((int)size)
                   .SetChunkStartPos(_startPos));
        }
예제 #2
0
 public long GetCheckpoint(string name, long dv = default(long))
 {
     using (var tx = _env.Read()) {
         return(Lmdb.GetStreamPosition(tx, name, dv));
     }
 }