Skip to content

Commit

Permalink
Merge pull request #44 from michaelPf85/patch-1
Browse files Browse the repository at this point in the history
Fix random Add-Content : Stream was not readable
  • Loading branch information
lipkau authored Mar 23, 2019
2 parents b5f3645 + 0582f9f commit 1b101ef
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions PSIni/Functions/Out-IniFile.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Set-StrictMode -Version Latest
Set-StrictMode -Version Latest
Function Out-IniFile {
<#
.Synopsis
Expand Down Expand Up @@ -132,8 +132,9 @@ Function Out-IniFile {
[ValidateNotNullOrEmpty()]
[ValidateScript( {Test-Path $_ -IsValid})]
[Parameter( Mandatory, ValueFromPipelineByPropertyName )]
[Alias("Path")]
[string]
$Path,
$FilePath,

[Parameter( Mandatory )]
$Delimiter,
Expand All @@ -149,13 +150,13 @@ Function Out-IniFile {
Foreach ($key in $InputObject.get_keys()) {
if ($key -match "^Comment\d+") {
Write-Verbose "$($MyInvocation.MyCommand.Name):: Writing comment: $key"
Add-Content -Value "$($InputObject[$key])" -Encoding $Encoding -Path $Path
"$($InputObject[$key])" | Out-File -Encoding $Encoding -FilePath $FilePath -Append
}
else {
Write-Verbose "$($MyInvocation.MyCommand.Name):: Writing key: $key"
$InputObject[$key] |
ForEach-Object { "$key$delimiter$_" } |
Add-Content -Encoding $Encoding -Path $Path
Out-File -Encoding $Encoding -FilePath $FilePath -Append
}
}
}
Expand All @@ -169,7 +170,7 @@ Function Out-IniFile {
# Splatting Parameters
$parameters = @{
Encoding = $Encoding;
Path = $FilePath
FilePath = $FilePath
}

}
Expand All @@ -193,7 +194,7 @@ Function Out-IniFile {
if (!($InputObject[$i].GetType().GetInterface('IDictionary'))) {
#Key value pair
Write-Verbose "$($MyInvocation.MyCommand.Name):: Writing key: $i"
Add-Content -Value "$i$delimiter$($InputObject[$i])" @parameters
"$i$delimiter$($InputObject[$i])" | Out-File -Append @parameters

}
elseif ($i -eq $script:NoSection) {
Expand All @@ -208,7 +209,7 @@ Function Out-IniFile {
Write-Verbose "$($MyInvocation.MyCommand.Name):: Writing Section: [$i]"

# Only write section, if it is not a dummy ($script:NoSection)
if ($i -ne $script:NoSection) { Add-Content -Value "$extraLF[$i]" @parameters }
if ($i -ne $script:NoSection) { "$extraLF[$i]" | Out-File -Append @parameters }
if ($Pretty) {
$extraLF = "`r`n"
}
Expand Down

0 comments on commit 1b101ef

Please sign in to comment.