简体   繁体   English

未指定名称字段的编码,任何非 ASCII 字节都将被丢弃

[英]No Encoding for Name field is specified, any non-ASCII bytes will be discarded

The following .NET 5.0 code using ICSharpCode.SharpZipLib以下 .NET 5.0 代码使用ICSharpCode.SharpZipLib

var gzipInputStream = new GZipInputStream(sourceStream);
var tarInputStream = new TarInputStream(gzipInputStream);

var gZipOutputStream = new GZipOutputStream(destinationStream);
var tarOutputStream = new TarOutputStream(gZipOutputStream);

now emits warnings现在发出警告

[CS0618] 'TarInputStream.TarInputStream(Stream)' is obsolete: 
    'No Encoding for Name field is specified, any non-ASCII bytes will be discarded'

[CS0618] 'TarOutputStream.TarOutputStream(Stream)' is obsolete: 
    'No Encoding for Name field is specified, any non-ASCII bytes will be discarded'

What Encoding should I specify when constructing TarInputStream and TarOutputStream ?构造TarInputStreamTarOutputStream时应该指定什么Encoding

The encoding you specify is dependent on the contents of the file, and is subject to what you are trying to achieve\support in your scenario.您指定的编码取决于文件的内容,并取决于您在场景中尝试实现\支持的内容。

Since it seems the default is ASCII, you actually don't 'need' to change\specify any Encoding at the moment.由于默认值似乎是 ASCII,因此您现在实际上不需要更改\指定任何编码。

In regards to the obsolete flag warning, If you're asking how to handle the warning and keep the default encoding, you could use TarOutputStream.TarOutputStream(Stream, null) ctor method signature.关于过时标志警告,如果您询问如何处理警告并保持默认编码,您可以使用TarOutputStream.TarOutputStream(Stream, null) ctor 方法签名。


Update (In reference to Maintainer's comments as well as responses to Github issue)更新(参考维护者的评论以及对 Github 问题的回复)

The default behavior of entry encoding process when specifying null in TarOutputStream.TarOutputStream(Stream, null) isTarOutputStream.TarOutputStream(Stream, null)中指定null时入口编码过程的默认行为是

no encoding conversion / just [copies] the lower 8 bits无编码转换/仅 [复制] 低 8 位

In regards to recommendation on specifying encoding:关于指定编码的建议:

If you don't know what encoding might have been used, the safest bet is often to specify UTF-8如果您不知道可能使用了哪种编码,最安全的选择通常是指定 UTF-8

As such, my recommendation is echoing that advice.因此,我的建议与该建议相呼应。 You call the non-obsolete constructor and specify Encoding.UTF8 .您调用非过时的构造函数并指定Encoding.UTF8

var gzipInputStream = new GZipInputStream(sourceStream);
var tarInputStream = new TarInputStream(gzipInputStream, Encoding.UTF8);

var gZipOutputStream = new GZipOutputStream(destinationStream);
var tarOutputStream = new TarOutputStream(gZipOutputStream, Encoding.UTF8);

thanks, @piksel bitworks and @Panagiotis Kanavos谢谢,@piksel bitworks 和 @Panagiotis Kanavos

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM