/// <summary> /// Compresses specified file and creates specified archive. /// </summary> /// <param name="fileName"></param> /// <param name="archiveName"></param> public void Compress(string fileName, string archiveName) { using (FileStream fileStream = new FileStream(fileName, FileMode.Open)) { using (FileStream archiveStream = new FileStream(archiveName, FileMode.OpenOrCreate)) { using (GZipStream compressStream = new GZipStream(archiveStream, CompressionMode.Compress)) { blockByBlockStreamWriter.Write(fileStream, compressStream); } } } }
/// <summary> /// Compresses specified file and creates specified archive. /// </summary> /// <param name="fileName"></param> /// <param name="archiveName"></param> public void Compress(string fileName, string archiveName) { try { using (FileStream fileStream = new FileStream(fileName, FileMode.Open)) { using (FileStream archiveStream = new FileStream(archiveName, FileMode.OpenOrCreate)) { using (GZipStream compressStream = new GZipStream(archiveStream, CompressionMode.Compress)) { blockByBlockStreamWriter.Write(fileStream, compressStream); } } } } catch (Exception ex) { File.Delete(archiveName); throw ex; } }