deflatestream

DeflateStream / GZipStream to CryptoStream and vice versa

☆樱花仙子☆ 提交于 2021-02-07 09:33:39
问题 I want to to compress and encrypt a file in one go by using this simple code: public void compress(FileInfo fi, Byte[] pKey, Byte[] pIV) { // Get the stream of the source file. using (FileStream inFile = fi.OpenRead()) { // Create the compressed encrypted file. using (FileStream outFile = File.Create(fi.FullName + ".pebf")) { using (CryptoStream encrypt = new CryptoStream(outFile, Rijndael.Create().CreateEncryptor(pKey, pIV), CryptoStreamMode.Write)) { using (DeflateStream cmprss = new

DeflateStream / GZipStream to CryptoStream and vice versa

寵の児 提交于 2021-02-07 09:30:42
问题 I want to to compress and encrypt a file in one go by using this simple code: public void compress(FileInfo fi, Byte[] pKey, Byte[] pIV) { // Get the stream of the source file. using (FileStream inFile = fi.OpenRead()) { // Create the compressed encrypted file. using (FileStream outFile = File.Create(fi.FullName + ".pebf")) { using (CryptoStream encrypt = new CryptoStream(outFile, Rijndael.Create().CreateEncryptor(pKey, pIV), CryptoStreamMode.Write)) { using (DeflateStream cmprss = new

Deflating data from MSZIP format

*爱你&永不变心* 提交于 2020-05-28 03:08:06
问题 I'm trying to read a compressed binary .x mesh file but my decompression is failing. The file is basically some directx header info and then a bunch of data in MSZIP format (i.e. 2 bytes are an int blockSize , 2 bytes are a "magic number" and then there are blockSize deflated bytes and then repeat until there's no more data) so for each block I'm just getting the compressed bytes and deflating like so- internal static byte[] DecompressBlock(byte[] data) { var result = new List<byte>(); var ms

Deflating data from MSZIP format

[亡魂溺海] 提交于 2020-05-28 03:07:06
问题 I'm trying to read a compressed binary .x mesh file but my decompression is failing. The file is basically some directx header info and then a bunch of data in MSZIP format (i.e. 2 bytes are an int blockSize , 2 bytes are a "magic number" and then there are blockSize deflated bytes and then repeat until there's no more data) so for each block I'm just getting the compressed bytes and deflating like so- internal static byte[] DecompressBlock(byte[] data) { var result = new List<byte>(); var ms

Deflating data from MSZIP format

喜夏-厌秋 提交于 2020-05-28 03:05:28
问题 I'm trying to read a compressed binary .x mesh file but my decompression is failing. The file is basically some directx header info and then a bunch of data in MSZIP format (i.e. 2 bytes are an int blockSize , 2 bytes are a "magic number" and then there are blockSize deflated bytes and then repeat until there's no more data) so for each block I'm just getting the compressed bytes and deflating like so- internal static byte[] DecompressBlock(byte[] data) { var result = new List<byte>(); var ms

Compressed content in a byte array to uncompressed in a string

我怕爱的太早我们不能终老 提交于 2020-01-14 03:08:27
问题 How can we create a simple function to take the compressed content from an array of byte (compressed with Deflate method, ANSI encoded) and express it in a string? I go with this one : public string UnzipString3(byte[] byteArrayCompressedContent) { int compressedSize = byteArrayCompressedContent.Length; try { using (MemoryStream inputMemoryStream = new MemoryStream(byteArrayCompressedContent)) { //I need to consume the first 2 bytes to be able read the stream //If I consume 0 or 4, I can't

Is it possible to use the .NET DeflateStream for pdf creation?

孤街浪徒 提交于 2019-12-19 08:00:12
问题 I'm playing around with the ability to create pdf files through C# code. I have been looking at the PDF specifications and have been able to create a working PDF file, done by taking strings of data and encoding them into byte arrays using the UTF8 Encoding. The problem I run into is when I try to use the DeflateStream on the pdf stream objects. It just doesn't seem to work: Here is the text version of the pdf object that is in question ( \r\n is at the end of each line, just not visible here

GZipStream and DeflateStream produce bigger files

非 Y 不嫁゛ 提交于 2019-12-19 05:46:48
问题 I'm trying to use deflate/gzip streams in C# but it appears that the files after compression are bigger than before. For example, I compress a docx file of 900ko, but it produce a 1.4Mo one ! And it does it for every file I tried. May be I am wrong in the way I'm doing it? Here is my code : FileStream input = File.OpenRead(Environment.CurrentDirectory + "/file.docx"); FileStream output = File.OpenWrite(Environment.CurrentDirectory + "/compressedfile.dat"); GZipStream comp = new GZipStream

zip and unzip string with Deflate

别说谁变了你拦得住时间么 提交于 2019-12-17 19:33:40
问题 I need to zip and unzip string Here is code: public static byte[] ZipStr(String str) { using (MemoryStream output = new MemoryStream()) using (DeflateStream gzip = new DeflateStream(output, CompressionMode.Compress)) using (StreamWriter writer = new StreamWriter(gzip)) { writer.Write(str); return output.ToArray(); } } and public static string UnZipStr(byte[] input) { using (MemoryStream inputStream = new MemoryStream(input)) using (DeflateStream gzip = new DeflateStream(inputStream,

Mono & DeflateStream

僤鯓⒐⒋嵵緔 提交于 2019-12-13 06:59:26
问题 I have a simple code byte[] buffer = Encoding.UTF8.GetBytes("abracadabra"); MemoryStream ms = new MemoryStream(); DeflateStream ds = new DeflateStream(ms, CompressionMode.Compress, false); ms.Write(buffer, 0, buffer.Length); DeflateStream ds2 = new DeflateStream(ms, CompressionMode.Decompress, false); byte[] buffer2 = new byte[ms.Length]; ds2.Read(buffer2, 0, (int)ms.Length); Console.WriteLine(Encoding.UTF8.GetString(buffer2)); And when reading from ds2, i have the following: Stacktrace: at