Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 54 additions & 6 deletions src/ICSharpCode.SharpZipLib/Tar/TarArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,22 @@ protected TarArchive(TarOutputStream stream)
/// </summary>
/// <param name="inputStream">The stream to retrieve archive data from.</param>
/// <returns>Returns a new <see cref="TarArchive"/> suitable for reading from.</returns>
[Obsolete("No Encoding for Name field is specified, any non-ASCII bytes will be discarded")]
public static TarArchive CreateInputTarArchive(Stream inputStream)
{
return CreateInputTarArchive(inputStream, null);
}

/// <summary>
/// The InputStream based constructors create a TarArchive for the
/// purposes of extracting or listing a tar archive. Thus, use
/// these constructors when you wish to extract files from or list
/// the contents of an existing tar archive.
/// </summary>
/// <param name="inputStream">The stream to retrieve archive data from.</param>
/// <param name="nameEncoding">The <see cref="Encoding"/> used for the Name fields, or null for ASCII only</param>
/// <returns>Returns a new <see cref="TarArchive"/> suitable for reading from.</returns>
public static TarArchive CreateInputTarArchive(Stream inputStream, Encoding nameEncoding)
{
if (inputStream == null)
{
Expand All @@ -116,7 +131,7 @@ public static TarArchive CreateInputTarArchive(Stream inputStream)
}
else
{
result = CreateInputTarArchive(inputStream, TarBuffer.DefaultBlockFactor);
result = CreateInputTarArchive(inputStream, TarBuffer.DefaultBlockFactor, nameEncoding);
}
return result;
}
Expand All @@ -127,7 +142,20 @@ public static TarArchive CreateInputTarArchive(Stream inputStream)
/// <param name="inputStream">A stream containing the tar archive contents</param>
/// <param name="blockFactor">The blocking factor to apply</param>
/// <returns>Returns a <see cref="TarArchive"/> suitable for reading.</returns>
[Obsolete("No Encoding for Name field is specified, any non-ASCII bytes will be discarded")]
public static TarArchive CreateInputTarArchive(Stream inputStream, int blockFactor)
{
return CreateInputTarArchive(inputStream, blockFactor, null);
}

/// <summary>
/// Create TarArchive for reading setting block factor
/// </summary>
/// <param name="inputStream">A stream containing the tar archive contents</param>
/// <param name="blockFactor">The blocking factor to apply</param>
/// <param name="nameEncoding">The <see cref="Encoding"/> used for the Name fields, or null for ASCII only</param>
/// <returns>Returns a <see cref="TarArchive"/> suitable for reading.</returns>
public static TarArchive CreateInputTarArchive(Stream inputStream, int blockFactor, Encoding nameEncoding)
{
if (inputStream == null)
{
Expand All @@ -139,15 +167,15 @@ public static TarArchive CreateInputTarArchive(Stream inputStream, int blockFact
throw new ArgumentException("TarInputStream not valid");
}

return new TarArchive(new TarInputStream(inputStream, blockFactor));
return new TarArchive(new TarInputStream(inputStream, blockFactor, nameEncoding));
}

/// <summary>
/// Create a TarArchive for writing to, using the default blocking factor
/// </summary>
/// <param name="outputStream">The <see cref="Stream"/> to write to</param>
/// <param name="nameEncoding"></param>
/// <returns>Returns a <see cref="TarArchive"/> suitable for writing.</returns>
public static TarArchive CreateOutputTarArchive(Stream outputStream)
public static TarArchive CreateOutputTarArchive(Stream outputStream, Encoding nameEncoding)
{
if (outputStream == null)
{
Expand All @@ -163,10 +191,19 @@ public static TarArchive CreateOutputTarArchive(Stream outputStream)
}
else
{
result = CreateOutputTarArchive(outputStream, TarBuffer.DefaultBlockFactor);
result = CreateOutputTarArchive(outputStream, TarBuffer.DefaultBlockFactor, nameEncoding);
}
return result;
}
/// <summary>
/// Create a TarArchive for writing to, using the default blocking factor
/// </summary>
/// <param name="outputStream">The <see cref="Stream"/> to write to</param>
/// <returns>Returns a <see cref="TarArchive"/> suitable for writing.</returns>
public static TarArchive CreateOutputTarArchive(Stream outputStream)
{
return CreateOutputTarArchive(outputStream, null);
}

/// <summary>
/// Create a <see cref="TarArchive">tar archive</see> for writing.
Expand All @@ -175,6 +212,17 @@ public static TarArchive CreateOutputTarArchive(Stream outputStream)
/// <param name="blockFactor">The blocking factor to use for buffering.</param>
/// <returns>Returns a <see cref="TarArchive"/> suitable for writing.</returns>
public static TarArchive CreateOutputTarArchive(Stream outputStream, int blockFactor)
{
return CreateOutputTarArchive(outputStream, blockFactor, null);
}
/// <summary>
/// Create a <see cref="TarArchive">tar archive</see> for writing.
/// </summary>
/// <param name="outputStream">The stream to write to</param>
/// <param name="blockFactor">The blocking factor to use for buffering.</param>
/// <param name="nameEncoding"></param>
/// <returns>Returns a <see cref="TarArchive"/> suitable for writing.</returns>
public static TarArchive CreateOutputTarArchive(Stream outputStream, int blockFactor, Encoding nameEncoding)
{
if (outputStream == null)
{
Expand All @@ -186,7 +234,7 @@ public static TarArchive CreateOutputTarArchive(Stream outputStream, int blockFa
throw new ArgumentException("TarOutputStream is not valid");
}

return new TarArchive(new TarOutputStream(outputStream, blockFactor));
return new TarArchive(new TarOutputStream(outputStream, blockFactor, nameEncoding));
}

#endregion Static factory methods
Expand Down
58 changes: 54 additions & 4 deletions src/ICSharpCode.SharpZipLib/Tar/TarEntry.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Text;

namespace ICSharpCode.SharpZipLib.Tar
{
Expand Down Expand Up @@ -49,10 +50,25 @@ private TarEntry()
/// <param name = "headerBuffer">
/// The header bytes from a tar archive entry.
/// </param>
public TarEntry(byte[] headerBuffer)
[Obsolete("No Encoding for Name field is specified, any non-ASCII bytes will be discarded")]
public TarEntry(byte[] headerBuffer) : this(headerBuffer, null)
{
}

/// <summary>
/// Construct an entry from an archive's header bytes. File is set
/// to null.
/// </summary>
/// <param name = "headerBuffer">
/// The header bytes from a tar archive entry.
/// </param>
/// <param name = "nameEncoding">
/// The <see cref="Encoding"/> used for the Name fields, or null for ASCII only
/// </param>
public TarEntry(byte[] headerBuffer, Encoding nameEncoding)
{
header = new TarHeader();
header.ParseBuffer(headerBuffer);
header.ParseBuffer(headerBuffer, nameEncoding);
}

/// <summary>
Expand Down Expand Up @@ -469,9 +485,24 @@ public TarEntry[] GetDirectoryEntries()
/// <param name = "outBuffer">
/// The tar entry header buffer to fill in.
/// </param>
[Obsolete("No Encoding for Name field is specified, any non-ASCII bytes will be discarded")]
public void WriteEntryHeader(byte[] outBuffer)
{
header.WriteHeader(outBuffer);
WriteEntryHeader(outBuffer, null);
}

/// <summary>
/// Write an entry's header information to a header buffer.
/// </summary>
/// <param name = "outBuffer">
/// The tar entry header buffer to fill in.
/// </param>
/// <param name = "nameEncoding">
/// The <see cref="Encoding"/> used for the Name fields, or null for ASCII only
/// </param>
public void WriteEntryHeader(byte[] outBuffer, Encoding nameEncoding)
{
header.WriteHeader(outBuffer, nameEncoding);
}

/// <summary>
Expand All @@ -484,9 +515,28 @@ public void WriteEntryHeader(byte[] outBuffer)
/// <param name="newName">
/// The new name to place into the header buffer.
/// </param>
[Obsolete("No Encoding for Name field is specified, any non-ASCII bytes will be discarded")]
static public void AdjustEntryName(byte[] buffer, string newName)
{
TarHeader.GetNameBytes(newName, buffer, 0, TarHeader.NAMELEN);
AdjustEntryName(buffer, newName, null);
}

/// <summary>
/// Convenience method that will modify an entry's name directly
/// in place in an entry header buffer byte array.
/// </summary>
/// <param name="buffer">
/// The buffer containing the entry header to modify.
/// </param>
/// <param name="newName">
/// The new name to place into the header buffer.
/// </param>
/// <param name="nameEncoding">
/// The <see cref="Encoding"/> used for the Name fields, or null for ASCII only
/// </param>
static public void AdjustEntryName(byte[] buffer, string newName, Encoding nameEncoding)
{
TarHeader.GetNameBytes(newName, buffer, 0, TarHeader.NAMELEN, nameEncoding);
}

/// <summary>
Expand Down
Loading