Skip to content

Commit e8b9e4c

Browse files
committed
Merge pull request #16 from icsharpcode/master
Merge from upstream
2 parents d9a25e1 + 875f335 commit e8b9e4c

13 files changed

Lines changed: 224 additions & 173 deletions

File tree

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ cache:
2525
# - "Documentation/nunit3-test-results-travis.xml"
2626
# skip_cleanup: true
2727
# on:
28-
# tags: true
28+
# tags: true

ICSharpCode.SharpZipLib.Samples/cs/CreateZipFile/CreateZipFile.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,15 @@ public static void Main(string[] args)
5454

5555
// 'using' statements guarantee the stream is closed properly which is a big source
5656
// of problems otherwise. Its exception safe as well which is great.
57-
using (ZipOutputStream s = new ZipOutputStream(File.Create(args[1]))) {
57+
using (ZipOutputStream s = new ZipOutputStream(File.Create(args[1])))
58+
{
5859

5960
s.SetLevel(9); // 0 - store only to 9 - means best compression
6061

6162
byte[] buffer = new byte[4096];
6263

63-
foreach (string file in filenames) {
64+
foreach (string file in filenames)
65+
{
6466

6567
// Using GetFileName makes the result compatible with XP
6668
// as the resulting path is not absolute.
@@ -80,7 +82,8 @@ public static void Main(string[] args)
8082
// Using a fixed size buffer here makes no noticeable difference for output
8183
// but keeps a lid on memory usage.
8284
int sourceBytes;
83-
do {
85+
do
86+
{
8487
sourceBytes = fs.Read(buffer, 0, buffer.Length);
8588
s.Write(buffer, 0, sourceBytes);
8689
} while (sourceBytes > 0);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace unzipfile
8+
{
9+
class Program
10+
{
11+
static void Main(string[] args)
12+
{
13+
}
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace viewzipfile
8+
{
9+
class Program
10+
{
11+
static void Main(string[] args)
12+
{
13+
}
14+
}
15+
}

ICSharpCode.SharpZipLib.Samples/vb/WpfCreateZipFile/WpfCreateZipFileWindow.xaml.vb

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -11,71 +11,71 @@ Class WpfCreateZipFileWindow
1111
' Add any initialization after the InitializeComponent() call.
1212
End Sub
1313

14-
Private Sub btnZipIt_Click(sender As Object, e As RoutedEventArgs) Handles btnZipIt.Click
15-
Dim sourceDir As String = tbSourceDir.Text.Trim()
14+
Private Sub btnZipIt_Click(sender As Object, e As RoutedEventArgs) Handles btnZipIt.Click
15+
Dim sourceDir As String = tbSourceDir.Text.Trim()
1616

17-
' Simple sanity checks
18-
If sourceDir.Length = 0 Then
19-
MessageBox.Show("Please specify a directory")
20-
Return
21-
Else
22-
If Not Directory.Exists(sourceDir) Then
23-
MessageBox.Show(sourceDir, "Directory not found")
24-
Return
25-
End If
26-
End If
17+
' Simple sanity checks
18+
If sourceDir.Length = 0 Then
19+
MessageBox.Show("Please specify a directory")
20+
Return
21+
Else
22+
If Not Directory.Exists(sourceDir) Then
23+
MessageBox.Show(sourceDir, "Directory not found")
24+
Return
25+
End If
26+
End If
2727

28-
Dim targetName As String = tbZipFileName.Text.Trim()
29-
If targetName.Length = 0 Then
30-
MessageBox.Show("No name specified", "Zip file name error")
31-
Return
32-
End If
28+
Dim targetName As String = tbZipFileName.Text.Trim()
29+
If targetName.Length = 0 Then
30+
MessageBox.Show("No name specified", "Zip file name error")
31+
Return
32+
End If
3333

34-
Dim astrFileNames() As String = Directory.GetFiles(sourceDir)
35-
Dim strmZipOutputStream As ZipOutputStream
34+
Dim astrFileNames() As String = Directory.GetFiles(sourceDir)
35+
Dim strmZipOutputStream As ZipOutputStream
3636

37-
strmZipOutputStream = New ZipOutputStream(File.Create(targetName))
37+
strmZipOutputStream = New ZipOutputStream(File.Create(targetName))
3838

39-
Try
39+
Try
4040

41-
REM Compression Level: 0-9
42-
REM 0: no(Compression)
43-
REM 9: maximum compression
44-
strmZipOutputStream.SetLevel(5)
41+
REM Compression Level: 0-9
42+
REM 0: no(Compression)
43+
REM 9: maximum compression
44+
strmZipOutputStream.SetLevel(5)
4545

46-
Dim strFile As String
47-
Dim abyBuffer(4096) As Byte
46+
Dim strFile As String
47+
Dim abyBuffer(4096) As Byte
4848

49-
For Each strFile In astrFileNames
50-
Dim strmFile As FileStream = File.OpenRead(strFile)
51-
Try
49+
For Each strFile In astrFileNames
50+
Dim strmFile As FileStream = File.OpenRead(strFile)
51+
Try
5252

53-
Dim objZipEntry As ZipEntry = New ZipEntry(strFile)
53+
Dim objZipEntry As ZipEntry = New ZipEntry(strFile)
5454

55-
objZipEntry.DateTime = DateTime.Now
56-
objZipEntry.Size = strmFile.Length
55+
objZipEntry.DateTime = DateTime.Now
56+
objZipEntry.Size = strmFile.Length
5757

58-
strmZipOutputStream.PutNextEntry(objZipEntry)
59-
StreamUtils.Copy(strmFile, strmZipOutputStream, abyBuffer)
60-
Finally
61-
strmFile.Close()
62-
End Try
63-
Next
58+
strmZipOutputStream.PutNextEntry(objZipEntry)
59+
StreamUtils.Copy(strmFile, strmZipOutputStream, abyBuffer)
60+
Finally
61+
strmFile.Close()
62+
End Try
63+
Next
6464

65-
strmZipOutputStream.Finish()
65+
strmZipOutputStream.Finish()
6666

67-
Finally
68-
strmZipOutputStream.Close()
69-
End Try
67+
Finally
68+
strmZipOutputStream.Close()
69+
End Try
7070

71-
MessageBox.Show("Operation complete")
72-
End Sub
71+
MessageBox.Show("Operation complete")
72+
End Sub
7373

74-
Private Sub btnBrowseForFolder_Click(sender As Object, e As RoutedEventArgs) Handles btnBrowseForFolder.Click
74+
Private Sub btnBrowseForFolder_Click(sender As Object, e As RoutedEventArgs) Handles btnBrowseForFolder.Click
7575
Dim FolderBrowserDialog As WpfFolderBrowserDialog
7676
FolderBrowserDialog = New WpfFolderBrowserDialog
77-
If FolderBrowserDialog.ShowDialog() = True Then
78-
tbSourceDir.Text = FolderBrowserDialog.FileName
79-
End If
80-
End Sub
77+
If FolderBrowserDialog.ShowDialog() = True Then
78+
tbSourceDir.Text = FolderBrowserDialog.FileName
79+
End If
80+
End Sub
8181
End Class

ICSharpCode.SharpZipLib/Checksum/Crc32.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ internal static uint ComputeCrc32(uint oldCrc, byte bval)
141141

142142
/// <summary>
143143
/// Initialise a default instance of <see cref="Crc32"></see>
144-
/// </summary>
144+
/// </summary>
145145
public Crc32()
146146
{
147147
Reset();

ICSharpCode.SharpZipLib/Tar/TarArchive.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,9 @@ public void ExtractContents(string destinationDirectory)
556556
break;
557557
}
558558

559+
if (entry.TarHeader.TypeFlag == TarHeader.LF_LINK || entry.TarHeader.TypeFlag == TarHeader.LF_SYMLINK)
560+
continue;
561+
559562
ExtractEntry(destinationDirectory, entry);
560563
}
561564
}

ICSharpCode.SharpZipLib/Tar/TarHeader.cs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ public class TarHeader : ICloneable
147147
/// </summary>
148148
public const int DEVLEN = 8;
149149

150+
/// <summary>
151+
/// The length of the name prefix field in a header buffer.
152+
/// </summary>
153+
public const int PREFIXLEN = 155;
154+
150155
//
151156
// LF_ constants represent the "type" of an entry
152157
//
@@ -597,21 +602,26 @@ public void ParseBuffer(byte[] header)
597602
Magic = ParseName(header, offset, MAGICLEN).ToString();
598603
offset += MAGICLEN;
599604

600-
Version = ParseName(header, offset, VERSIONLEN).ToString();
601-
offset += VERSIONLEN;
605+
if (Magic == "ustar")
606+
{
607+
Version = ParseName(header, offset, VERSIONLEN).ToString();
608+
offset += VERSIONLEN;
602609

603-
UserName = ParseName(header, offset, UNAMELEN).ToString();
604-
offset += UNAMELEN;
610+
UserName = ParseName(header, offset, UNAMELEN).ToString();
611+
offset += UNAMELEN;
605612

606-
GroupName = ParseName(header, offset, GNAMELEN).ToString();
607-
offset += GNAMELEN;
613+
GroupName = ParseName(header, offset, GNAMELEN).ToString();
614+
offset += GNAMELEN;
608615

609-
DevMajor = (int)ParseOctal(header, offset, DEVLEN);
610-
offset += DEVLEN;
616+
DevMajor = (int) ParseOctal(header, offset, DEVLEN);
617+
offset += DEVLEN;
611618

612-
DevMinor = (int)ParseOctal(header, offset, DEVLEN);
619+
DevMinor = (int) ParseOctal(header, offset, DEVLEN);
620+
offset += DEVLEN;
613621

614-
// Fields past this point not currently parsed or used...
622+
string prefix = ParseName(header, offset, PREFIXLEN).ToString();
623+
if (!string.IsNullOrEmpty(prefix)) Name = prefix + '/' + Name;
624+
}
615625

616626
isChecksumValid = Checksum == TarHeader.MakeCheckSum(header);
617627
}
@@ -870,8 +880,8 @@ public static int GetNameBytes(string name, int nameOffset, byte[] buffer, int b
870880
}
871881

872882
int i;
873-
874-
for (i = 0; i < length - 1 && nameOffset + i < name.Length; ++i) {
883+
884+
for (i = 0 ; i < length && nameOffset + i < name.Length; ++i) {
875885
buffer[bufferOffset + i] = (byte)name[nameOffset + i];
876886
}
877887

ICSharpCode.SharpZipLib/Tar/TarInputStream.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,8 @@ public TarEntry GetNextEntry()
491491
headerBuf = this.tarBuffer.ReadBlock();
492492
} else if (header.TypeFlag != TarHeader.LF_NORMAL &&
493493
header.TypeFlag != TarHeader.LF_OLDNORM &&
494+
header.TypeFlag != TarHeader.LF_LINK &&
495+
header.TypeFlag != TarHeader.LF_SYMLINK &&
494496
header.TypeFlag != TarHeader.LF_DIR) {
495497
// Ignore things we dont understand completely for now
496498
SkipToNextEntry();

ICSharpCode.SharpZipLib/Tar/TarOutputStream.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,15 @@ public void PutNextEntry(TarEntry entry)
274274
throw new ArgumentNullException(nameof(entry));
275275
}
276276

277-
if (entry.TarHeader.Name.Length >= TarHeader.NAMELEN) {
277+
if (entry.TarHeader.Name.Length > TarHeader.NAMELEN) {
278278
var longHeader = new TarHeader();
279279
longHeader.TypeFlag = TarHeader.LF_GNU_LONGNAME;
280280
longHeader.Name = longHeader.Name + "././@LongLink";
281-
longHeader.UserId = 0;
282-
longHeader.GroupId = 0;
283-
longHeader.GroupName = "";
284-
longHeader.UserName = "";
281+
longHeader.Mode = 420;//644 by default
282+
longHeader.UserId = entry.UserId;
283+
longHeader.GroupId = entry.GroupId;
284+
longHeader.GroupName = entry.GroupName;
285+
longHeader.UserName = entry.UserName;
285286
longHeader.LinkName = "";
286287
longHeader.Size = entry.TarHeader.Name.Length + 1; // Plus one to avoid dropping last char
287288

0 commit comments

Comments
 (0)