Skip to content

function to read file bytes using System.IO.BinaryReader

Notifications You must be signed in to change notification settings

santisq/Read-Bytes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 

Repository files navigation

Read-Bytes

DESCRIPTION

PowerShell function that reads file bytes using System.IO.BinaryReady. It can read all bytes, last n bytes (-Last) or first n bytes (-First).
Pipeline compatible with System.IO.FileInfo.

PARAMETER

  • -Path <string> Absolute or relative file path. Alias FullName.
  • [-First <long>] Specifies the number of Bytes from the beginning of a file.
  • [-Last <long>] Specifies the number of Bytes from the end of a file.
  • [<CommonParameters>]

OUTPUT PSCustomObject

Name Type Description
FilePath String Absolute File Path
Length Int64 File Length in Bytes
Bytes Object[] Array containing the File Bytes

REQUIREMENTS

  • Tested and compatible with PowerShell v5.1 and PowerShell Core.

EXAMPLES

  • Get-ChildItem . -File | Read-Bytes -Last 100: Reads the last 100 bytes of all files on the current folder. If the -Last argument exceeds the file length, it reads the entire file.
  • Get-ChildItem . -File | Read-Bytes -First 100: Reads the first 100 bytes of all files on the current folder. If the -First argument exceeds the file length, it reads the entire file.
  • Read-Bytes -Path path/to/file.ext: Reads all bytes of file.ext.

OUTPUT

FilePath                            Length Bytes
--------                            ------ -----
/home/user/Documents/test/......        14 {73, 32, 119, 111…}
/home/user/Documents/test/......         0 
/home/user/Documents/test/......         0 
/home/user/Documents/test/......         0 
/home/user/Documents/test/......       116 {111, 109, 101, 95…}
/home/user/Documents/test/......     17963 {50, 101, 101, 53…}
/home/user/Documents/test/......      3617 {105, 32, 110, 111…}
/home/user/Documents/test/......       638 {101, 109, 112, 116…}
/home/user/Documents/test/......         0 
/home/user/Documents/test/......        36 {65, 99, 114, 101…}
/home/user/Documents/test/......       735 {117, 112, 46, 79…}
/home/user/Documents/test/......      1857 {108, 111, 115, 101…}
/home/user/Documents/test/......        77 {79, 80, 69, 78…}

About

function to read file bytes using System.IO.BinaryReader

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published