使用CSharp在Mac上压缩文件

时间:2011-05-20 04:17:11

标签: macos mono sharpziplib

我正在使用mono和monobjc来开发在Mac OS X 10.6上运行的应用程序。我正在使用ICSharpCode.SharpZip将一些文件添加到zip文件中。代码是 -

var ms = new MemoryStream();
var zipStream = new ZipOutputStream(ms); 
zipStream.PutNextEntry(new ZipEntry(Path.GetFileName(file))
         {DateTime = File.GetCreationTime(file), 
          Size = new FileInfo(file).Length});

有时,并非总是如此,PutNewEntry代码会抛出以下异常 -

System.NotSupportedException:不支持CodePage 437     在System.Text.Encoding.GetEncoding(Int32代码页)[0x00000]中:0       at ICSharpCode.SharpZipLib.Zip.ZipConstants.ConvertToArray(System.String str)[0x00000] in:0   at ICSharpCode.SharpZipLib.Zip.ZipConstants.ConvertToArray(Int32 flags,System.String str)[0x00000] in:0   at ICSharpCode.SharpZipLib.Zip.ZipOutputStream.PutNextEntry(ICSharpCode.SharpZipLib.Zip.ZipEntry entry)[0x00000] in:0   at(wrapper remoting-invoke-with-check)ICSharpCode.SharpZipLib.Zip.ZipOutputStream:PutNextEntry(ICSharpCode.SharpZipLib.Zip.ZipEntry)

我有以下两个问题 -

  1. 造成上述异常的原因是什么。
  2. 看起来ICSharp可能不是最好的选择。有哪些更好的选择?

1 个答案:

答案 0 :(得分:0)

我通过创建tar.gzip而不是使用zip来修复此问题。我使用ICSharp本身来创建tar文件。 Mac似乎不喜欢拉链。这也可能是因为我在Mac端使用Mono框架中的ICSharp并在​​Windows端使用ICSharp(从网上下载)。但是使用tar.gzip解决了这个问题。

相关问题