Skip to content

Commit

Permalink
Merge pull request #1 from hsitin/nitish-fix_open_streamReader
Browse files Browse the repository at this point in the history
Closed the open file stream
  • Loading branch information
hsitin authored Apr 24, 2018
2 parents dd668fa + db4b578 commit 8ee4ca4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion PSYaml/PSYaml.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'PSYaml.psm1'

# Version number of this module.
ModuleVersion = '1.0.2'
ModuleVersion = '1.0.3'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
23 changes: 16 additions & 7 deletions PSYaml/Public/ConvertFrom-Yaml.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,26 @@ function ConvertFrom-Yaml {
BEGIN { }
PROCESS
{
If($Path){
$streamReader = [System.IO.File]::OpenText($Path)
try {
If($Path) {
$streamReader = [System.IO.File]::OpenText($Path)
}
Else {
$streamReader = new-object System.IO.StringReader([string]$yamlString)
}

$yamlStream = New-Object YamlDotNet.RepresentationModel.YamlStream
$yamlStream.Load([System.IO.TextReader]$streamReader)
ConvertFrom-YAMLDocument ($yamlStream.Documents[0])
}
Else{
$stringReader = new-object System.IO.StringReader([string]$yamlString)
$yamlStream = New-Object YamlDotNet.RepresentationModel.YamlStream
$yamlStream.Load([System.IO.TextReader]$stringReader)
ConvertFrom-YAMLDocument ($yamlStream.Documents[0])
Catch {
Write-Error $_
}
Finally {
if ($streamReader.Basestream -ne $null)
{
$streamReader.Close()
}
}
}
END {}
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Author: Phil-Factor, Brian Marsh
## Release Notes
| Version | Change Log |
| :-------: | ----------------------------------------------------------------- |
| 1.0.3 | Closed the open YAML file if error occurs in it during parsing |
| 1.0.2 | Reformated several sections for readability, added pester tests |
| 1.0.1 | Converted single psm1 file to multiple public/private functions |

Expand Down

0 comments on commit 8ee4ca4

Please sign in to comment.