Skip to content

Commit

Permalink
Support custom compression levels. Fix #12
Browse files Browse the repository at this point in the history
  • Loading branch information
gdivis committed Nov 20, 2018
1 parent f1a01ab commit 9a4c52b
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/Inedo.UPack/Packaging/UniversalPackageBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,25 @@ public UniversalPackageBuilder(string fileName, UniversalPackageMetadata metadat
/// <param name="timestamp">Timestamp to record for the entry.</param>
/// <param name="cancellationToken">Cancellation token for asynchronous operations.</param>
/// <exception cref="ArgumentNullException"><paramref name="stream"/> is null or <paramref name="path"/> is null or empty.</exception>
public async Task AddFileRawAsync(Stream stream, string path, DateTimeOffset timestamp, CancellationToken cancellationToken)
public Task AddFileRawAsync(Stream stream, string path, DateTimeOffset timestamp, CancellationToken cancellationToken) => this.AddFileRawAsync(stream, path, timestamp, CompressionLevel.Optimal, cancellationToken);
/// <summary>
/// Copies the data in the specified stream to the package using the specified raw path (relative to archive root) and timestamp.
/// </summary>
/// <param name="stream">Source stream to copy from.</param>
/// <param name="path">Raw path of entry to create in the package (relative to archive root).</param>
/// <param name="timestamp">Timestamp to record for the entry.</param>
/// <param name="compressionLevel">Compression level to use for the added file.</param>
/// <param name="cancellationToken">Cancellation token for asynchronous operations.</param>
/// <exception cref="ArgumentNullException"><paramref name="stream"/> is null or <paramref name="path"/> is null or empty.</exception>
public async Task AddFileRawAsync(Stream stream, string path, DateTimeOffset timestamp, CompressionLevel compressionLevel, CancellationToken cancellationToken)
{
if (stream == null)
throw new ArgumentNullException(nameof(stream));
if (string.IsNullOrEmpty(path))
throw new ArgumentNullException(nameof(path));

var p = path.Replace('\\', '/').Trim('/');
var entry = this.zip.CreateEntry(p);
var entry = this.zip.CreateEntry(p, compressionLevel);
entry.LastWriteTime = timestamp;
using (var entryStream = entry.Open())
{
Expand All @@ -94,14 +104,24 @@ public async Task AddFileRawAsync(Stream stream, string path, DateTimeOffset tim
/// <param name="timestamp">Timestamp to record for the entry.</param>
/// <param name="cancellationToken">Cancellation token for asynchronous operations.</param>
/// <exception cref="ArgumentNullException"><paramref name="stream"/> is null or <paramref name="path"/> is null or empty.</exception>
public Task AddFileAsync(Stream stream, string path, DateTimeOffset timestamp, CancellationToken cancellationToken)
public Task AddFileAsync(Stream stream, string path, DateTimeOffset timestamp, CancellationToken cancellationToken) => this.AddFileAsync(stream, path, timestamp, CompressionLevel.Optimal, cancellationToken);
/// <summary>
/// Copies the data in the specified stream to the package using the specified content path (relative to package directory) and timestamp.
/// </summary>
/// <param name="stream">Source stream to copy from.</param>
/// <param name="path">Path of entry to create in the package (relative to package directory).</param>
/// <param name="timestamp">Timestamp to record for the entry.</param>
/// <param name="compressionLevel">Compression level to use for the added file.</param>
/// <param name="cancellationToken">Cancellation token for asynchronous operations.</param>
/// <exception cref="ArgumentNullException"><paramref name="stream"/> is null or <paramref name="path"/> is null or empty.</exception>
public Task AddFileAsync(Stream stream, string path, DateTimeOffset timestamp, CompressionLevel compressionLevel, CancellationToken cancellationToken)
{
if (stream == null)
throw new ArgumentNullException(nameof(stream));
if (string.IsNullOrEmpty(path))
throw new ArgumentNullException(nameof(path));

return this.AddFileRawAsync(stream, "package/" + path.Trim('/', '\\'), timestamp, cancellationToken);
return this.AddFileRawAsync(stream, "package/" + path.Trim('/', '\\'), timestamp, compressionLevel, cancellationToken);
}
/// <summary>
/// Creates an entry for an empty directory in the package using the specified raw path (relative to archive root).
Expand Down

0 comments on commit 9a4c52b

Please sign in to comment.