什么是 ICSharpCode.SharpZipLib.ZipEntry.Flag?

发布于 2024-10-04 03:49:02 字数 313 浏览 0 评论 0原文

有人可以举个例子吗,我用谷歌搜索但没有找到任何合适的结果。

我想给出标志,以便在文件名带有特殊字符的情况下使用原始名称压缩文件。

例如,目前我正在使用

ZipEntry entry = new ZipEntry(file.FullName.Substring(directory.FullName.Length + 1));
                    entry.Flags |= 2048; // enable UTF8 file names

什么标志来支持特殊字符文件名?

谢谢

Will any one please give an example, I googled but not found any suitable result.

I want to give flag so that it compress the file with its original name in case of file name

with special characters.for example currently I am using

ZipEntry entry = new ZipEntry(file.FullName.Substring(directory.FullName.Length + 1));
                    entry.Flags |= 2048; // enable UTF8 file names

what should be the flag to support special charaters file name??

Thanx

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

总以为 2024-10-11 03:49:02

此组件的源代码可在此处获取:

http://www.icsharpcode.net/opensource/ Sharpziplib/Download.aspx

如果您下载源代码并查看 ZipEntry 的代码,您将发现 Flags 属性的以下注释。

///
/// Get/Set general purpose bit flag for entry
///
///
/// General purpose bit flag
///
/// Bit 0: If set, indicates the file is encrypted
/// Bit 1-2 Only used for compression type 6 Imploding, and 8, 9 deflating
/// Imploding:
/// Bit 1 if set indicates an 8K sliding dictionary was used.  If clear a 4k dictionary was used
/// Bit 2 if set indicates 3 Shannon-Fanno trees were used to encode the sliding dictionary, 2 otherwise
///
/// Deflating:
///   Bit 2    Bit 1
///     0        0       Normal compression was used
///     0        1       Maximum compression was used
///     1        0       Fast compression was used
///     1        1       Super fast compression was used
///
/// Bit 3: If set, the fields crc-32, compressed size
/// and uncompressed size are were not able to be written during zip file creation
/// The correct values are held in a data descriptor immediately following the compressed data.
/// Bit 4: Reserved for use by PKZIP for enhanced deflating
/// Bit 5: If set indicates the file contains compressed patch data
/// Bit 6: If set indicates strong encryption was used.
/// Bit 7-10: Unused or reserved
/// Bit 11: If set the name and comments for this entry are in <a href="http://www.unicode.org">unicode</a>.
/// Bit 12-15: Unused or reserved
///
/// <seealso cref="IsUnicodeText"></seealso>
/// <seealso cref="IsCrypted"></seealso>

因此,像您所做的那样,将 2048 与 Flags 进行“或”运算看起来是正确的。或者,您可以设置 IsUnicodeText 属性,该属性执行相同的操作,但使代码看起来更简洁:

entry.IsUnicodeText = true;

Source code for this component is available here:

http://www.icsharpcode.net/opensource/sharpziplib/Download.aspx

If you download the source and review the code for ZipEntry, you'll find the following comments for the Flags property.

///
/// Get/Set general purpose bit flag for entry
///
///
/// General purpose bit flag
///
/// Bit 0: If set, indicates the file is encrypted
/// Bit 1-2 Only used for compression type 6 Imploding, and 8, 9 deflating
/// Imploding:
/// Bit 1 if set indicates an 8K sliding dictionary was used.  If clear a 4k dictionary was used
/// Bit 2 if set indicates 3 Shannon-Fanno trees were used to encode the sliding dictionary, 2 otherwise
///
/// Deflating:
///   Bit 2    Bit 1
///     0        0       Normal compression was used
///     0        1       Maximum compression was used
///     1        0       Fast compression was used
///     1        1       Super fast compression was used
///
/// Bit 3: If set, the fields crc-32, compressed size
/// and uncompressed size are were not able to be written during zip file creation
/// The correct values are held in a data descriptor immediately following the compressed data.
/// Bit 4: Reserved for use by PKZIP for enhanced deflating
/// Bit 5: If set indicates the file contains compressed patch data
/// Bit 6: If set indicates strong encryption was used.
/// Bit 7-10: Unused or reserved
/// Bit 11: If set the name and comments for this entry are in <a href="http://www.unicode.org">unicode</a>.
/// Bit 12-15: Unused or reserved
///
/// <seealso cref="IsUnicodeText"></seealso>
/// <seealso cref="IsCrypted"></seealso>

So, ORing 2048 into Flags as you have done looks correct. Or, you could set the IsUnicodeText property which does the same thing, though makes the code look a little cleaner:

entry.IsUnicodeText = true;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文