tags:

views:

39

answers:

1

Hi all, 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?

+1  A: 

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

x0n
Thanks Oisin, that is to say, it seems that I shouldn't use Unknown for something of another to use it.
hoge