You've already forked linux-packaging-mono
Imported Upstream version 5.0.0.42
Former-commit-id: fd56571888259555122d8a0f58c68838229cea2b
This commit is contained in:
parent
1190d13a04
commit
6bdd276d05
@@ -4,8 +4,12 @@ include ../../build/rules.make
|
||||
|
||||
LIBRARY = System.IO.Compression.FileSystem.dll
|
||||
LIB_REFS = System System.IO.Compression
|
||||
LIB_MCS_FLAGS =
|
||||
LIB_MCS_FLAGS = -unsafe
|
||||
TEST_MCS_FLAGS =
|
||||
TEST_LIB_REFS = System System.Core System.IO.Compression
|
||||
|
||||
RESX_RESOURCE_STRING = \
|
||||
../../../external/corefx/src/System.IO.Compression.FileSystem/src/Resources/Strings.resx \
|
||||
../../../external/corefx/src/System.Buffers/src/Resources/Strings.resx
|
||||
|
||||
include ../../build/library.make
|
||||
|
@@ -1,5 +1,14 @@
|
||||
AssemblyInfo.cs
|
||||
ZipFile.cs
|
||||
ZipFileExtensions.cs
|
||||
../../build/common/Consts.cs
|
||||
../../build/common/MonoTODOAttribute.cs
|
||||
|
||||
corefx/SR.cs
|
||||
|
||||
../../../external/corefx/src/Common/src/System/IO/PathInternal.CaseSensitivity.cs
|
||||
../../../external/corefx/src/System.IO.Compression.ZipFile/src/System/IO/Compression/ZipFile.cs
|
||||
../../../external/corefx/src/System.IO.Compression.ZipFile/src/System/IO/Compression/ZipFileExtensions.cs
|
||||
|
||||
../../../external/corefx/src/System.Buffers/src/System/Buffers/ArrayPool.cs
|
||||
../../../external/corefx/src/System.Buffers/src/System/Buffers/ArrayPoolEventSource.cs
|
||||
../../../external/corefx/src/System.Buffers/src/System/Buffers/DefaultArrayPool.cs
|
||||
../../../external/corefx/src/System.Buffers/src/System/Buffers/DefaultArrayPoolBucket.cs
|
||||
../../../external/corefx/src/System.Buffers/src/System/Buffers/Utilities.cs
|
@@ -1,182 +0,0 @@
|
||||
//
|
||||
// ZipFile.cs
|
||||
//
|
||||
// Author:
|
||||
// JoĂŁo Matos <joao.matos@xamarin.com>
|
||||
// Martin Baulig <martin.baulig@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2013 Xamarin Inc. (http://www.xamarin.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace System.IO.Compression
|
||||
{
|
||||
public static class ZipFile
|
||||
{
|
||||
public static void CreateFromDirectory (
|
||||
string sourceDirectoryName, string destinationArchiveFileName)
|
||||
{
|
||||
CreateFromDirectory (sourceDirectoryName, destinationArchiveFileName,
|
||||
CompressionLevel.Fastest, includeBaseDirectory: false);
|
||||
}
|
||||
|
||||
public static void CreateFromDirectory (
|
||||
string sourceDirectoryName, string destinationArchiveFileName,
|
||||
CompressionLevel compressionLevel, bool includeBaseDirectory)
|
||||
{
|
||||
CreateFromDirectory (sourceDirectoryName, destinationArchiveFileName,
|
||||
compressionLevel, includeBaseDirectory, Encoding.UTF8);
|
||||
}
|
||||
|
||||
public static void CreateFromDirectory (
|
||||
string sourceDirectoryName,
|
||||
string destinationArchiveFileName,
|
||||
CompressionLevel compressionLevel,
|
||||
bool includeBaseDirectory,
|
||||
Encoding entryNameEncoding)
|
||||
{
|
||||
if (sourceDirectoryName == null)
|
||||
throw new ArgumentNullException ("sourceDirectoryName");
|
||||
|
||||
if (destinationArchiveFileName == null)
|
||||
throw new ArgumentNullException ("destinationArchiveFileName");
|
||||
|
||||
if (string.IsNullOrWhiteSpace (sourceDirectoryName))
|
||||
throw new ArgumentException ("sourceDirectoryName");
|
||||
|
||||
if (string.IsNullOrWhiteSpace (destinationArchiveFileName))
|
||||
throw new ArgumentException ("destinationArchiveFileName");
|
||||
|
||||
if (entryNameEncoding == Encoding.Unicode ||
|
||||
entryNameEncoding == Encoding.UTF32 ||
|
||||
entryNameEncoding == Encoding.UTF7)
|
||||
throw new ArgumentException ("entryNameEncoding");
|
||||
|
||||
if (entryNameEncoding == null)
|
||||
entryNameEncoding = Encoding.UTF8;
|
||||
|
||||
if (!Directory.Exists (sourceDirectoryName))
|
||||
throw new DirectoryNotFoundException ("sourceDirectoryName is invalid or does not exist");
|
||||
|
||||
var sourceDir = new DirectoryInfo (Path.GetFullPath (sourceDirectoryName));
|
||||
|
||||
string fullBaseName = sourceDir.FullName;
|
||||
if (includeBaseDirectory && sourceDir.Parent != null)
|
||||
fullBaseName = sourceDir.Parent.FullName;
|
||||
|
||||
bool hasEntries = false;
|
||||
char[] separators = new char[] {
|
||||
Path.DirectorySeparatorChar,
|
||||
Path.AltDirectorySeparatorChar
|
||||
};
|
||||
|
||||
using (var zipFile = ZipFile.Open (destinationArchiveFileName, ZipArchiveMode.Create,
|
||||
entryNameEncoding)) {
|
||||
var entries = sourceDir.EnumerateFileSystemInfos ("*", SearchOption.AllDirectories);
|
||||
foreach (var entry in entries) {
|
||||
hasEntries = true;
|
||||
|
||||
int length = entry.FullName.Length - fullBaseName.Length;
|
||||
string entryName = entry.FullName.Substring(fullBaseName.Length, length);
|
||||
|
||||
entryName = entryName.TrimStart(separators);
|
||||
|
||||
if (entry is FileInfo)
|
||||
zipFile.CreateEntryFromFile (entry.FullName, entryName, compressionLevel);
|
||||
else
|
||||
zipFile.CreateEntry (entryName + Path.DirectorySeparatorChar);
|
||||
}
|
||||
|
||||
// Create the base directory even if we had no entries
|
||||
if (includeBaseDirectory && !hasEntries)
|
||||
zipFile.CreateEntry(sourceDir.Name + Path.DirectorySeparatorChar);
|
||||
}
|
||||
}
|
||||
|
||||
public static void ExtractToDirectory (
|
||||
string sourceArchiveFileName, string destinationDirectoryName)
|
||||
{
|
||||
ExtractToDirectory (sourceArchiveFileName, destinationDirectoryName,
|
||||
Encoding.UTF8);
|
||||
}
|
||||
|
||||
public static void ExtractToDirectory (
|
||||
string sourceArchiveFileName, string destinationDirectoryName,
|
||||
Encoding entryNameEncoding)
|
||||
{
|
||||
if (sourceArchiveFileName == null)
|
||||
throw new ArgumentNullException ("sourceArchiveFileName");
|
||||
|
||||
using (ZipArchive zipArchive = ZipFile.Open(sourceArchiveFileName,
|
||||
ZipArchiveMode.Read, entryNameEncoding))
|
||||
{
|
||||
zipArchive.ExtractToDirectory(destinationDirectoryName);
|
||||
}
|
||||
}
|
||||
|
||||
public static ZipArchive Open (
|
||||
string archiveFileName, ZipArchiveMode mode)
|
||||
{
|
||||
return Open (archiveFileName, mode, entryNameEncoding: null);
|
||||
}
|
||||
|
||||
public static ZipArchive Open (
|
||||
string archiveFileName, ZipArchiveMode mode,
|
||||
Encoding entryNameEncoding)
|
||||
{
|
||||
if (archiveFileName == null)
|
||||
throw new ArgumentNullException ("archiveFileName");
|
||||
|
||||
if (string.IsNullOrWhiteSpace (archiveFileName))
|
||||
throw new ArgumentException ("archiveFileName");
|
||||
|
||||
FileStream stream;
|
||||
|
||||
switch (mode) {
|
||||
case ZipArchiveMode.Read:
|
||||
if (!File.Exists (archiveFileName))
|
||||
throw new FileNotFoundException ();
|
||||
stream = new FileStream (archiveFileName, FileMode.Open, FileAccess.Read,
|
||||
FileShare.Read);
|
||||
break;
|
||||
case ZipArchiveMode.Create:
|
||||
if (File.Exists (archiveFileName))
|
||||
throw new IOException ("mode is set to Create but the file already exists");
|
||||
stream = new FileStream (archiveFileName, FileMode.CreateNew, FileAccess.Write);
|
||||
break;
|
||||
case ZipArchiveMode.Update:
|
||||
stream = new FileStream (archiveFileName, FileMode.OpenOrCreate,
|
||||
FileAccess.ReadWrite);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException ();
|
||||
}
|
||||
|
||||
return new ZipArchive (stream, mode, false, entryNameEncoding);
|
||||
}
|
||||
|
||||
public static ZipArchive OpenRead (string archiveFileName)
|
||||
{
|
||||
return ZipFile.Open (archiveFileName, ZipArchiveMode.Read);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,124 +0,0 @@
|
||||
//
|
||||
// ZipFileExtensions.cs
|
||||
//
|
||||
// Author:
|
||||
// JoĂŁo Matos <joao.matos@xamarin.com>
|
||||
// Martin Baulig <martin.baulig@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2013 Xamarin Inc. (http://www.xamarin.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System;
|
||||
|
||||
namespace System.IO.Compression
|
||||
{
|
||||
public static class ZipFileExtensions
|
||||
{
|
||||
public static ZipArchiveEntry CreateEntryFromFile (
|
||||
this ZipArchive destination, string sourceFileName,
|
||||
string entryName)
|
||||
{
|
||||
return CreateEntryFromFile (destination, sourceFileName, entryName,
|
||||
CompressionLevel.Fastest);
|
||||
}
|
||||
|
||||
public static ZipArchiveEntry CreateEntryFromFile (
|
||||
this ZipArchive destination, string sourceFileName,
|
||||
string entryName, CompressionLevel compressionLevel)
|
||||
{
|
||||
if (destination == null)
|
||||
throw new ArgumentNullException ("destination");
|
||||
|
||||
if (sourceFileName == null)
|
||||
throw new ArgumentNullException ("sourceFileName");
|
||||
|
||||
if (entryName == null)
|
||||
throw new ArgumentNullException ("entryName");
|
||||
|
||||
ZipArchiveEntry entry;
|
||||
using (Stream stream = File.Open (sourceFileName, FileMode.Open,
|
||||
FileAccess.Read, FileShare.Read))
|
||||
{
|
||||
var zipArchiveEntry = destination.CreateEntry (entryName, compressionLevel);
|
||||
zipArchiveEntry.LastWriteTime = File.GetLastWriteTimeUtc(sourceFileName);
|
||||
|
||||
using (Stream entryStream = zipArchiveEntry.Open ())
|
||||
stream.CopyTo (entryStream);
|
||||
|
||||
entry = zipArchiveEntry;
|
||||
}
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
public static void ExtractToDirectory (
|
||||
this ZipArchive source,
|
||||
string destinationDirectoryName)
|
||||
{
|
||||
if (source == null)
|
||||
throw new ArgumentNullException ("source");
|
||||
|
||||
if (destinationDirectoryName == null)
|
||||
throw new ArgumentNullException ("destinationDirectoryName");
|
||||
|
||||
var destDirInfo = Directory.CreateDirectory (destinationDirectoryName);
|
||||
string fullName = destDirInfo.FullName;
|
||||
|
||||
foreach (var zipEntry in source.Entries)
|
||||
{
|
||||
var fullPath = Path.GetFullPath (Path.Combine (fullName, zipEntry.FullName));
|
||||
|
||||
var isFileName = Path.GetFileName (fullPath).Length != 0;
|
||||
var dirPath = isFileName ? Path.GetDirectoryName (fullPath) : fullPath;
|
||||
Directory.CreateDirectory (dirPath);
|
||||
|
||||
if (isFileName)
|
||||
zipEntry.ExtractToFile (fullPath, false);
|
||||
}
|
||||
}
|
||||
|
||||
public static void ExtractToFile (
|
||||
this ZipArchiveEntry source,
|
||||
string destinationFileName)
|
||||
{
|
||||
ExtractToFile (source, destinationFileName, overwrite: false);
|
||||
}
|
||||
|
||||
public static void ExtractToFile (
|
||||
this ZipArchiveEntry source, string destinationFileName,
|
||||
bool overwrite)
|
||||
{
|
||||
if (source == null)
|
||||
throw new ArgumentNullException ("source");
|
||||
|
||||
if (destinationFileName == null)
|
||||
throw new ArgumentNullException ("destinationFileName");
|
||||
|
||||
var mode = overwrite ? FileMode.Create : FileMode.CreateNew;
|
||||
using (var stream = File.Open (destinationFileName, mode, FileAccess.Write))
|
||||
{
|
||||
using (var stream2 = source.Open ())
|
||||
stream2.CopyTo(stream);
|
||||
}
|
||||
|
||||
File.SetLastWriteTime(destinationFileName, source.LastWriteTime.DateTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
10
mcs/class/System.IO.Compression.FileSystem/corefx/SR.cs
Normal file
10
mcs/class/System.IO.Compression.FileSystem/corefx/SR.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
//
|
||||
// This file was generated by resx2sr tool
|
||||
//
|
||||
|
||||
partial class SR
|
||||
{
|
||||
public const string IO_DirectoryNameWithData = "Zip entry name ends in directory separator character but contains data.";
|
||||
public const string IO_ExtractingResultsInOutside = "Extracting Zip entry would have resulted in a file outside the specified destination directory.";
|
||||
public const string ArgumentException_BufferNotFromPool = "The buffer is not associated with this pool and may not be returned to it.";
|
||||
}
|
Reference in New Issue
Block a user