本文整理汇总了C#中ICSharpCode.SharpZipLib.Zip.ZipNameTransform类的典型用法代码示例。如果您正苦于以下问题:C# ZipNameTransform类的具体用法?C# ZipNameTransform怎么用?C# ZipNameTransform使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ZipNameTransform类属于ICSharpCode.SharpZipLib.Zip命名空间,在下文中一共展示了ZipNameTransform类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WebTemplateGeneratorHost
public WebTemplateGeneratorHost(Hashtable globalContext)
{
_globalContext = globalContext;
_outputStream = new MemoryStream();
_zipOutput = new ZipOutputStream(_outputStream);
_zipOutput.SetLevel(9);
_zipNameTransform = new ZipNameTransform();
}
示例2: Build
public Stream Build (string archiveFileName)
{
ArgumentUtility.CheckNotNullOrEmpty ("archiveFileName", archiveFileName);
using (var zipOutputStream = new ZipOutputStream (File.Create (archiveFileName)))
{
foreach (var fileInfo in _files)
{
var directoryName = fileInfo.Directory == null ? string.Empty : fileInfo.Directory.FullName;
var nameTransform = new ZipNameTransform (directoryName);
if (fileInfo is IFileInfo)
AddFileToZipFile ((IFileInfo) fileInfo, zipOutputStream, nameTransform);
else if (fileInfo is IDirectoryInfo)
AddDirectoryToZipFile ((IDirectoryInfo) fileInfo, zipOutputStream, nameTransform);
}
}
_files.Clear();
_currentFileIndex = 0;
_currentTotalValueExcludingCurrentFileValue = 0;
return File.Open (archiveFileName, FileMode.Open, FileAccess.Read, FileShare.None);
}
示例3: ZipEntryFactory
/// <summary>
/// Initialise a new instance of <see cref="ZipEntryFactory"/> using the specified <see cref="DateTime"/>
/// </summary>
/// <param name="time">The time to set all <see cref="ZipEntry.DateTime"/> values to.</param>
public ZipEntryFactory(DateTime time)
{
timeSetting_ = TimeSetting.Fixed;
FixedDateTime = time;
nameTransform_ = new ZipNameTransform();
}
示例4: CreateZip
/// <summary>
/// Create a zip archive sending output to the <paramref name="outputStream"/> passed.
/// </summary>
/// <param name="outputStream">The stream to write archive data to.</param>
/// <param name="sourceDirectory">The directory to source files from.</param>
/// <param name="recurse">True to recurse directories, false for no recursion.</param>
/// <param name="fileFilter">The <see cref="PathFilter">file filter</see> to apply.</param>
/// <param name="directoryFilter">The <see cref="PathFilter">directory filter</see> to apply.</param>
/// <remarks>The <paramref name="outputStream"/> is closed after creation.</remarks>
public void CreateZip(Stream outputStream, string sourceDirectory, bool recurse, string fileFilter, string directoryFilter)
{
NameTransform = new ZipNameTransform(sourceDirectory);
sourceDirectory_ = sourceDirectory;
using ( outputStream_ = new ZipOutputStream(outputStream) ) {
if ( password_ != null ) {
outputStream_.Password = password_;
}
outputStream_.UseZip64 = UseZip64;
var scanner = new IsolatedFileSystemScanner(fileFilter, directoryFilter);
scanner.ProcessFile += ProcessFile;
if ( CreateEmptyDirectories ) {
scanner.ProcessDirectory += ProcessDirectory;
}
if (events_ != null) {
if ( events_.FileFailure != null ) {
scanner.FileFailure += events_.FileFailure;
}
if ( events_.DirectoryFailure != null ) {
scanner.DirectoryFailure += events_.DirectoryFailure;
}
}
scanner.Scan(sourceDirectory, recurse);
}
}
示例5: TooLong
public void TooLong()
{
ZipNameTransform zt = new ZipNameTransform();
string veryLong = new string('x', 65536);
try {
zt.TransformDirectory(veryLong);
Assert.Fail("Expected an exception");
}
catch (PathTooLongException) {
}
}
示例6: PathalogicalNames
public void PathalogicalNames()
{
string badName = ".*:\\zy3$";
Assert.IsFalse(ZipNameTransform.IsValidName(badName));
ZipNameTransform t = new ZipNameTransform();
string result = t.TransformFile(badName);
Assert.IsTrue(ZipNameTransform.IsValidName(result));
}
示例7: NameTransforms
public void NameTransforms()
{
INameTransform t = new ZipNameTransform(@"C:\Slippery");
Assert.AreEqual("Pongo/Directory/", t.TransformDirectory(@"C:\Slippery\Pongo\Directory"), "Value should be trimmed and converted");
Assert.AreEqual("PoNgo/Directory/", t.TransformDirectory(@"c:\slipperY\PoNgo\Directory"), "Trimming should be case insensitive");
Assert.AreEqual("slippery/Pongo/Directory/", t.TransformDirectory(@"d:\slippery\Pongo\Directory"), "Trimming should be case insensitive");
Assert.AreEqual("Pongo/File", t.TransformFile(@"C:\Slippery\Pongo\File"), "Value should be trimmed and converted");
}
示例8: CreateZip
/// <summary>
/// Create a zip archive sending output to the <paramref name="outputStream"/> passed.
/// </summary>
/// <param name="outputStream">The stream to write archive data to.</param>
/// <param name="sourceDirectory">The directory to source files from.</param>
/// <param name="recurse">True to recurse directories, false for no recursion.</param>
/// <param name="fileFilter">The <see cref="PathFilter">file filter</see> to apply.</param>
/// <param name="directoryFilter">The <see cref="PathFilter">directory filter</see> to apply.</param>
public void CreateZip(Stream outputStream, string sourceDirectory, bool recurse, string fileFilter, string directoryFilter)
{
NameTransform = new ZipNameTransform(sourceDirectory);
sourceDirectory_ = sourceDirectory;
using ( outputStream_ = new ZipOutputStream(outputStream) ) {
FileSystemScanner scanner = new FileSystemScanner(fileFilter, directoryFilter);
scanner.ProcessFile += new ProcessFileDelegate(ProcessFile);
if ( this.CreateEmptyDirectories ) {
scanner.ProcessDirectory += new ProcessDirectoryDelegate(ProcessDirectory);
}
if (events_ != null) {
if ( events_.FileFailure != null ) {
scanner.FileFailure += events_.FileFailure;
}
if ( events_.DirectoryFailure != null ) {
scanner.DirectoryFailure += events_.DirectoryFailure;
}
}
scanner.Scan(sourceDirectory, recurse);
}
}
示例9: Basic
public void Basic()
{
ZipNameTransform t = new ZipNameTransform();
TestFile(t, "abcdef", "abcdef");
TestFile(t, @"\\uncpath\d1\file1", "file1");
TestFile(t, @"C:\absolute\file2", "absolute/file2");
// This is ignored but could be converted to 'file3'
TestFile(t, @"./file3", "./file3");
// The following relative paths cant be handled and are ignored
TestFile(t, @"../file3", "../file3");
TestFile(t, @".../file3", ".../file3");
// Trick filenames.
TestFile(t, @".....file3", ".....file3");
TestFile(t, @"c::file", "_file");
}
示例10: IsolatedZipEntryFactory
/// <summary>
/// Initialise a new instance of the <see cref="ZipEntryFactory"/> class.
/// </summary>
/// <remarks>A default <see cref="INameTransform"/>, and the LastWriteTime for files is used.</remarks>
public IsolatedZipEntryFactory()
{
nameTransform_ = new ZipNameTransform();
}
示例11: TestFile
void TestFile(ZipNameTransform t, string original, string expected)
{
string transformed = t.TransformFile(original);
Assert.AreEqual(expected, transformed, "Should be equal");
}
示例12: CreateZip
/// <summary>
/// Create a zip file.
/// </summary>
/// <param name="zipFileName">The name of the zip file to create.</param>
/// <param name="sourceDirectory">The directory to source files from.</param>
/// <param name="recurse">True to recurse directories, false for no recursion.</param>
/// <param name="fileFilter">The file filter to apply.</param>
/// <param name="directoryFilter">The directory filter to apply.</param>
public void CreateZip(string zipFileName, string sourceDirectory, bool recurse, string fileFilter, string directoryFilter)
{
NameTransform = new ZipNameTransform(true, sourceDirectory);
this.sourceDirectory = sourceDirectory;
outputStream = new ZipOutputStream(File.Create(zipFileName));
try {
FileSystemScanner scanner = new FileSystemScanner(fileFilter, directoryFilter);
scanner.ProcessFile += new ProcessFileDelegate(ProcessFile);
if ( this.CreateEmptyDirectories ) {
scanner.ProcessDirectory += new ProcessDirectoryDelegate(ProcessDirectory);
}
scanner.Scan(sourceDirectory, recurse);
}
finally {
outputStream.Close();
}
}
示例13: AddFileToZipFile
private void AddFileToZipFile (IFileInfo fileInfo, ZipOutputStream zipOutputStream, ZipNameTransform nameTransform)
{
var fileStream = GetFileStream (fileInfo);
var fileLength = fileInfo.Length;
if (fileStream == null)
return;
var zipEntry = CreateZipFileEntry (fileInfo, nameTransform);
zipOutputStream.PutNextEntry (zipEntry);
using (fileStream)
{
var streamCopier = new StreamCopier();
streamCopier.TransferProgress += (sender, args) => OnZippingProgress (args, fileInfo.FullName);
if (!streamCopier.CopyStream (fileStream, zipOutputStream))
{
zipEntry.Size = -1;
throw new AbortException();
}
}
_currentFileIndex++;
_currentTotalValueExcludingCurrentFileValue += fileLength;
}
示例14: AddDirectoryToZipFile
private void AddDirectoryToZipFile (IDirectoryInfo directoryInfo, ZipOutputStream zipOutputStream, ZipNameTransform nameTransform)
{
foreach (var file in directoryInfo.GetFiles ())
AddFileToZipFile (file, zipOutputStream, nameTransform);
foreach (var directory in directoryInfo.GetDirectories ())
AddDirectoryToZipFile (directory, zipOutputStream, nameTransform);
}
示例15: CreateZip
/// <summary>
/// Create a zip archive sending output to the <paramref name="outputStream"/> passed.
/// </summary>
/// <param name="outputStream">The stream to write archive data to.</param>
/// <param name="sourceDirectory">The directory to source files from.</param>
/// <param name="recurse">True to recurse directories, false for no recursion.</param>
/// <param name="fileFilter">The <see cref="PathFilter">file filter</see> to apply.</param>
/// <param name="directoryFilter">The <see cref="PathFilter">directory filter</see> to apply.</param>
public void CreateZip(Stream outputStream, string sourceDirectory, bool recurse, string fileFilter, string directoryFilter)
{
NameTransform = new ZipNameTransform(sourceDirectory);
sourceDirectory_ = sourceDirectory;
using ( outputStream_ = new ZipOutputStream(outputStream) ) {
#if !NETCF_1_0
if ( password_ != null ) {
outputStream_.Password = password_;
}
#endif
FileSystemScanner scanner = new FileSystemScanner(fileFilter, directoryFilter);
scanner.ProcessFile += new ProcessFileHandler(ProcessFile);
if ( this.CreateEmptyDirectories ) {
scanner.ProcessDirectory += new ProcessDirectoryHandler(ProcessDirectory);
}
if (events_ != null) {
if ( events_.FileFailure != null ) {
scanner.FileFailure += events_.FileFailure;
}
if ( events_.DirectoryFailure != null ) {
scanner.DirectoryFailure += events_.DirectoryFailure;
}
}
scanner.Scan(sourceDirectory, recurse);
}
}