SharpZipLib 在解压缩压缩文件时返回垃圾字符
SharpZipLib returning junk characters when unzipping compressed file
我正在尝试使用 sharpziplib 解压缩一些文件。问题是,它返回垃圾字符而不是特殊字符和日文字符。在将文件放入 zip 文件之前,是否有将文件名转换为 unicode 的方法?
我目前有以下代码。
foreach (ZipEntry zipEntry in zf)
{
zipEntry.IsUnicodeText = true;
if (!zipEntry.IsFile)
{
continue;
}
所以我 运行 不幸尝试使用 sharpziplib 解码这些文件。我切换到 dotnetzip 并将编码更改为 932,而 sharpziplib 在解压缩时似乎没有?我要回答我自己的问题,因为我没有看到很多关于这个问题的参考资料,也没有看到其他人将来可能会遇到这个问题。
using (ZipFile archive = new ZipFile(archiveFilenameIn, Encoding.GetEncoding(932)))
{
archive.Password = password;
archive.Encryption = EncryptionAlgorithm.PkzipWeak;
archive.StatusMessageTextWriter = Console.Out;
String fullZipToPath = Path.Combine(outFolder, Path.GetFileNameWithoutExtension(archiveFilenameIn));
//string directoryName = Path.GetDirectoryName(fullZipToPath);
if (fullZipToPath.Length > 0)
Directory.CreateDirectory(fullZipToPath);
archive.ExtractAll(fullZipToPath, ExtractExistingFileAction.Throw);
}
编辑:所以我玩弄了 sharpziplib,结果发现我可以设置默认代码页。之后一切正常。
ZipConstants.DefaultCodePage = 932;
我正在尝试使用 sharpziplib 解压缩一些文件。问题是,它返回垃圾字符而不是特殊字符和日文字符。在将文件放入 zip 文件之前,是否有将文件名转换为 unicode 的方法? 我目前有以下代码。
foreach (ZipEntry zipEntry in zf)
{
zipEntry.IsUnicodeText = true;
if (!zipEntry.IsFile)
{
continue;
}
所以我 运行 不幸尝试使用 sharpziplib 解码这些文件。我切换到 dotnetzip 并将编码更改为 932,而 sharpziplib 在解压缩时似乎没有?我要回答我自己的问题,因为我没有看到很多关于这个问题的参考资料,也没有看到其他人将来可能会遇到这个问题。
using (ZipFile archive = new ZipFile(archiveFilenameIn, Encoding.GetEncoding(932)))
{
archive.Password = password;
archive.Encryption = EncryptionAlgorithm.PkzipWeak;
archive.StatusMessageTextWriter = Console.Out;
String fullZipToPath = Path.Combine(outFolder, Path.GetFileNameWithoutExtension(archiveFilenameIn));
//string directoryName = Path.GetDirectoryName(fullZipToPath);
if (fullZipToPath.Length > 0)
Directory.CreateDirectory(fullZipToPath);
archive.ExtractAll(fullZipToPath, ExtractExistingFileAction.Throw);
}
编辑:所以我玩弄了 sharpziplib,结果发现我可以设置默认代码页。之后一切正常。
ZipConstants.DefaultCodePage = 932;