Exemplo n.º 1
0
        public Stream GetStream()
        {
            Stream stream = new Substream(
                new FileStream(ArchiveFilename, FileMode.Open, FileAccess.Read, FileShare.Read),
                (long)offset,
                length);

            switch (Compression)
            {
            case ArchiveFileCompression.LZ4:
                return(new LZ4Stream(stream,
                                     LZ4StreamMode.Decompress));

            case ArchiveFileCompression.Zstandard:
                byte[] output;
                using (MemoryStream buffer = new MemoryStream())
                {
                    stream.CopyTo(buffer);
                    output = buffer.ToArray();
                }
                using (ZstdNet.Decompressor zstd = new ZstdNet.Decompressor())
                    return(new MemoryStream(zstd.Unwrap(output), false));    //, (int)_size

            case ArchiveFileCompression.Uncompressed:
                return(stream);

            default:
                throw new InvalidOperationException("Compression type is invalid.");
            }
        }
Exemplo n.º 2
0
        public static byte[] GetMd5(Stream stream, long offset, long length)
        {
            MD5       md5 = MD5.Create();
            Substream sub = new Substream(stream, offset, length);

            return(md5.ComputeHash(sub));
        }