public override void Save(string resultFilePath, string includedFilesPath) { using (FileStream archUsTar = File.Create(resultFilePath)) { using (GZipWriter gZip = new GZipWriter(archUsTar)) { foreach (var file in FileMap) { string destFileName = file.Value; string sourceFilePath = file.Key; if (sourceFilePath.Contains(ExecutionContext.PACKAGE_SOURCE_TAG)) { sourceFilePath = sourceFilePath.Replace(ExecutionContext.PACKAGE_SOURCE_TAG, includedFilesPath); } string incPath = PACKAGE_INCLUDED_FILES_DIRECTORY; if (destFileName == MAIN_PACKAGE_FILENAME) { incPath = ""; } if (File.Exists(sourceFilePath)) { // сохранение файлов using (FileStream sourceFileStream = new FileStream(sourceFilePath, FileMode.Open, FileAccess.Read)) { destFileName = Path.Combine(incPath, destFileName); gZip.Write(sourceFileStream, destFileName); } } else if (Directory.Exists(sourceFilePath)) { // сохранение папок IOUtil.IterateDirectory(sourceFilePath, (fullPath) => { string relativePath = fullPath.Substring(sourceFilePath.Length + 1); relativePath = Path.Combine(destFileName, relativePath); relativePath = Path.Combine(incPath, relativePath); if (Directory.Exists(fullPath)) { gZip.Write(null, relativePath); } else { using (FileStream sourceFileStream = new FileStream(fullPath, FileMode.Open, FileAccess.Read)) { gZip.Write(sourceFileStream, relativePath); } } }); } } } } }
public void GZip_Writer() { using (Stream stream = File.Open(Path.Combine(SCRATCH_FILES_PATH, "Tar.tar.gz"), FileMode.OpenOrCreate, FileAccess.Write)) using (var writer = new GZipWriter(stream)) { writer.Write("Tar.tar", Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar")); } CompareArchivesByPath(Path.Combine(SCRATCH_FILES_PATH, "Tar.tar.gz"), Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar.gz")); }
public void GZip_Writer_Entry_Path_With_Dir() { using (Stream stream = File.Open(Path.Combine(SCRATCH_FILES_PATH, "Tar.tar.gz"), FileMode.OpenOrCreate, FileAccess.Write)) using (var writer = new GZipWriter(stream)) { var path = Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar"); writer.Write(path, path); //covers issue #532 } CompareArchivesByPath(Path.Combine(SCRATCH_FILES_PATH, "Tar.tar.gz"), Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar.gz")); }
protected override void SaveTo(Stream stream, CompressionInfo compressionInfo, IEnumerable <GZipArchiveEntry> oldEntries, IEnumerable <GZipArchiveEntry> newEntries) { if (this.Entries.Count > 1) { throw new InvalidOperationException("Only one entry is allowed in a GZip Archive"); } using (GZipWriter writer = new GZipWriter(stream)) { foreach (GZipArchiveEntry entry in Enumerable.Where <GZipArchiveEntry>(Enumerable.Concat <GZipArchiveEntry>(oldEntries, newEntries), delegate(GZipArchiveEntry x) { return(!x.IsDirectory); })) { using (Stream stream2 = entry.OpenEntryStream()) { writer.Write(entry.Key, stream2, entry.LastModifiedTime); } } } }
protected override void SaveTo(Stream stream, CompressionInfo compressionInfo, IEnumerable <GZipArchiveEntry> oldEntries, IEnumerable <GZipArchiveEntry> newEntries) { if (Entries.Count > 1) { throw new InvalidOperationException("Only one entry is allowed in a GZip Archive"); } using (var writer = new GZipWriter(stream)) { foreach (var entry in oldEntries.Concat(newEntries) .Where(x => !x.IsDirectory)) { using (var entryStream = entry.OpenEntryStream()) { writer.Write(entry.FilePath, entryStream, entry.LastModifiedTime); } } } }
/// <summary> /// Sends a single <see cref="GelfMessage" /> to GrayLog. /// </summary> /// <param name="message">The <see cref="GelfMessage" /> to send.</param> public void Send(GelfMessage message) { var msgBytes = _messageSerializer.SerializeToStringBytes(message); if (msgBytes.Length > MinMessageSizeBeforeCompressing) { using (var inputStream = new MemoryStream(msgBytes)) using (var outputStream = new MemoryStream(msgBytes.Length)) using (var writer = new GZipWriter(outputStream, new GZipWriterOptions() { CompressionType = CompressionType.GZip, LeaveStreamOpen = false })) { writer.Write(string.Empty, inputStream); msgBytes = outputStream.GetBuffer(); } } using (var udpClient = new UdpClient()) foreach (var bytes in _chunkEncoder.Encode(msgBytes)) { udpClient.Send(bytes, bytes.Length, GetEndPoint()); } }