Beispiel #1
0
        /// <summary>
        /// Writes the contents of a stream into the entry, overwriting any previous data.
        /// </summary>
        /// <param name="stream">The stream to copy from</param>
        /// <exception cref="IOException"/>
        public override async Task SetData(Stream stream)
        {
            _newData?.Dispose();
            _newData = new MemoryStream();
            using FlowbishStream flowbishStream = new FlowbishStream(_newData, FlowbishStreamMode.Encipher, ShortName + ".gz", true);
            if (stream.CanSeek)
            {
                await SegsStream.CompressStream(stream, flowbishStream);
            }
            else
            {
                using MemoryStream memStream = new MemoryStream();
                await stream.CopyToAsync(memStream);

                memStream.Position = 0;
                await SegsStream.CompressStream(memStream, flowbishStream);
            }
        }
Beispiel #2
0
        public async Task CompressUncompressTest(string inputFile)
        {
            using (FileStream fileStream = new FileStream(inputFile, FileMode.Open, FileAccess.Read))
            {
                using FileStream outStream = new FileStream("temp.dat", FileMode.Create, FileAccess.Write);
                await SegsStream.CompressStream(fileStream, outStream);
            }
            using (FileStream compStream = new FileStream("temp.dat", FileMode.Open, FileAccess.Read))
            {
                using SegsStream segsStream = new SegsStream(compStream, SegsStreamMode.Decompress);
                using FileStream outStream  = new FileStream("temp2.dat", FileMode.Create, FileAccess.Write);
                segsStream.CopyTo(outStream);
            }
            bool eq = Compare.CompareFiles(inputFile, "temp2.dat");

            File.Delete("temp.dat");
            File.Delete("temp2.dat");
            Assert.IsTrue(eq);
        }