({{, (RefLink[BinaryRead, paclet:ref/BinaryRead])[stream]
reads one byte of raw binary data from an input stream, and returns an integer from 0 to 255. }, {, (RefLink[BinaryRead, paclet:ref/BinaryRead])[stream,type]
reads an object of the specified type. }, {, (RefLink[BinaryRead, paclet:ref/BinaryRead])[stream,{(Subscript[type, 1]),(Subscript[type, 2]),…}]
reads a sequence of objects of the specified types.}})

OpenersNotesSection(Spacer1)Details and Options

Possible types to read are:

The first argument to (RefLink[BinaryRead, paclet:ref/BinaryRead]) can be (RefLink[InputStream, paclet:ref/InputStream])["name",n], or simply "name" if there is at most one open input stream with the specified name. (RefLink[BinaryRead, paclet:ref/BinaryRead]) will call (RefLink[OpenRead, paclet:ref/OpenRead]) open files with no associated stream.

(RefLink[BinaryRead, paclet:ref/BinaryRead])[(RefLink[File, paclet:ref/File])["file"],…] is also supported.

You can open a file or pipe to get an (RefLink[InputStream, paclet:ref/InputStream]) object using (RefLink[OpenRead, paclet:ref/OpenRead]).

Streams for use with (RefLink[BinaryRead, paclet:ref/BinaryRead]) should be opened with (RefLink[BinaryFormat, paclet:ref/BinaryFormat])->(RefLink[True, paclet:ref/True]).

There is always a "current point" maintained for any stream. When you read an object from a stream, the current point is left after the input you read. Successive calls to (RefLink[BinaryRead, paclet:ref/BinaryRead]) can therefore be used to read successive objects in a stream such as a file.

(RefLink[BinaryRead, paclet:ref/BinaryRead]) returns (RefLink[EndOfFile, paclet:ref/EndOfFile]) if you are at the end of the file.

(RefLink[BinaryRead, paclet:ref/BinaryRead]) returns (RefLink[Infinity, paclet:ref/Infinity]) for IEEE "infinity", and (RefLink[Indeterminate, paclet:ref/Indeterminate]) for IEEE "not-a-number".

The following options can be given:

OpenersPrimaryExamplesSection(Spacer1)Examples  (2)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

Create a file with a sequence of bytes:

file = FileNameJoin[{$TemporaryDirectory,"test1"}];

BinaryWrite[file, {8,97,255}];

Close[file];

Read the first byte from the file:

BinaryRead[file]

Read the second byte as an 8-bit character:

BinaryRead[file, "Character8"]

Read the next byte as an 8-bit signed integer:

BinaryRead[file, "Integer8"]

Close the file:

Close[file];

OpenersExampleSection1(Spacer1)Scope  (1)

Read bytes from the file specified using (RefLink[File, paclet:ref/File]) object:

file =File[FileNameJoin[{ $TemporaryDirectory,"test1"}]]

BinaryWrite[file,{65,66}];

Close[file]

BinaryRead[file,"Byte"]

BinaryRead[file,"Byte"]

Close[file];

DeleteFile[file]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[BinaryReadList, paclet:ref/BinaryReadList])  ▪  (RefLink[BinaryWrite, paclet:ref/BinaryWrite])  ▪  (RefLink[ByteArray, paclet:ref/ByteArray])  ▪  (RefLink[Read, paclet:ref/Read])  ▪  (RefLink[Import, paclet:ref/Import])  ▪  (RefLink[ImportString, paclet:ref/ImportString])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Binary Files, paclet:tutorial/BinaryFiles])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Binary Data, paclet:guide/BinaryData])}, {▪(RefLinkPlain[Using Connected Devices, paclet:guide/UsingConnectedDevices])}, {▪(RefLinkPlain[Network Programming, paclet:guide/NetworkProgramming])}, {▪(RefLinkPlain[Free-Form & External Input, paclet:guide/FreeFormAndExternalInput])}, {▪(RefLinkPlain[Low-Level File Operations, paclet:guide/LowLevelFileOperations])}, {▪(RefLinkPlain[Files, paclet:guide/Files])}, {▪(RefLinkPlain[Raspberry Pi, paclet:guide/RaspberryPi])}, {▪(RefLinkPlain[External Operations, paclet:guide/ExternalOperations])}, {▪(RefLinkPlain[Direct Control of External Processes, paclet:guide/DirectControlOfExternalProcesses])}, {▪(RefLinkPlain[Systems-Related String Operations, paclet:guide/SystemsRelatedStringOperations])}})}})