Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public byte[] Compress(string path)
- {
- MemoryStream stream;
- using (FileStream fileStream = File.Open(path, FileMode.Open, FileAccess.Read))
- {
- using (MemoryStream zipToCreate = new MemoryStream())
- {
- using (ZipArchive archive = new ZipArchive(zipToCreate, ZipArchiveMode.Create, true))
- {
- ZipArchiveEntry fileEntry = archive.CreateEntry(Path.GetFileName(path));
- using (var entryStream = fileEntry.Open())
- {
- fileStream.CopyTo(entryStream);
- }
- stream = zipToCreate;
- }
- }
- }
- return stream.ToArray();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement