C# 将pdf压缩为zip文件而不保存为文件
所以我在byte[]中有一个pdf,目前我正在从byte[]创建文件,对其进行压缩,然后将压缩文件转换为byte[]以再次发送。 我正在使用这个代码C# 将pdf压缩为zip文件而不保存为文件,c#,.net,compression,C#,.net,Compression,所以我在byte[]中有一个pdf,目前我正在从byte[]创建文件,对其进行压缩,然后将压缩文件转换为byte[]以再次发送。 我正在使用这个代码 System.IO.File.WriteAllBytes("./temp/pdffile.pdf", pdfbytes); //creates pdf file con temp folder //Zip the pdf file st
System.IO.File.WriteAllBytes("./temp/pdffile.pdf", pdfbytes); //creates pdf file con temp folder
//Zip the pdf file
string startPath = @".\temp";
string zipPath = @".\tempzip\zipedfile.zip";
ZipFile.CreateFromDirectory(startPath, zipPath); //zips the pdf file and creates de .zip file on the tempzip folder
string zipFilePath = "./tempzip/zipedfile.zip";
byte[] btes = System.IO.File.ReadAllBytes(zipFilePath); // encodes the zip file
我想知道的是,是否有可能在不保存文件的情况下,将pdf字节[]压缩成pdf文件,并将压缩字节[]全部存储在内存中?这是否回答了您的问题?