开发者

When should 'Unknown' be used as -Encoding parameter?

I was thinking Unknown option is used for binary files concatenation.

http://technet.microsoft.com/en-us/library/dd315299.aspx

Unknown The encoding type is unknown or invalid. The data can be treated as binary.

But {Get-Content binary.dat -Encoding Unknown} doesn't return byte array but string array.

PS > $a = Get-Content $PSHOME\WTRInstaller.ico -Encoding Unknown
PS > $b = Get-Content $PSHOME\WTRInstaller.ico -Encoding Byte

PS > $a[0].GetType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----      开发者_运维知识库                               --------
True     True     String                                   System.Object

PS > $b[0].GetType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     Byte                                     System.ValueType

Even if I convert $a to byte array, it doesn't coincide with $b.

PS > [Text.Encoding]::Unicode.GetBytes($a)
PS > compare $c[0..10] $b[0..10]

                                                InputObject SideIndicator
                                                ----------- -------------
                                                         10 =>
                                                         32 <=

When should 'Unknown' be used?


Uknown is not something that is supplied, but rather something that is returned. System.Text.Encoding is not just for use by powershell. There are many areas in the BCL that accept or return the same enums. Some values are for return, others for supplying.

-Oisin

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜