7 lines
924 B
PowerShell
7 lines
924 B
PowerShell
Set-StrictMode -Version Latest
|
|
function Read-NativeJson([string]$Path) { Get-Content -LiteralPath $Path -Raw | ConvertFrom-Json }
|
|
function Get-NativeHash([string]$Path) { (Get-FileHash -LiteralPath $Path -Algorithm SHA256).Hash.ToLowerInvariant() }
|
|
function Get-NativeRecord([string]$Path) { [ordered]@{path=$Path;bytes=(Get-Item -LiteralPath $Path).Length;sha256=(Get-NativeHash $Path)} }
|
|
function Assert-NativeFiles($Files) { foreach($entry in $Files) { if ((Get-Item -LiteralPath $entry.path).Length -ne $entry.bytes -or (Get-NativeHash $entry.path) -cne $entry.sha256) { throw "Bound file changed: $($entry.path)" } } }
|
|
function Write-NativeJson([string]$Path,$Value) { $json=$Value|ConvertTo-Json -Depth 20; $bytes=[Text.UTF8Encoding]::new($false).GetBytes($json+[Environment]::NewLine); $stream=[IO.File]::Open($Path,[IO.FileMode]::CreateNew); try {$stream.Write($bytes,0,$bytes.Length)} finally {$stream.Dispose()} }
|