Skip to content

Commit

Permalink
Add BASE64 support
Browse files Browse the repository at this point in the history
  • Loading branch information
niheaven committed Mar 28, 2019
1 parent 77245fc commit 667e773
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/persist.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ function persist_def_obj($persist) {
$glue = $persist.glue
}
if ($type -eq "file") {
$persist_def.content = $persist.content -join $glue
if ($persist.base64) {
$persist_def.content = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($persist.content -join ''))
} else {
$persist_def.content = $persist.content -join $glue
}
} else {
$persist_def.content = $null
}
Expand Down
3 changes: 3 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@
"merge",
"update"
]
},
"base64": {
"type": "boolean"
}
},
"type": "object"
Expand Down
8 changes: 7 additions & 1 deletion test/Scoop-Persist.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,17 @@ describe 'persist parsing' -Tag 'Scoop' {
$persist_def.target | should -be "foo"
$persist_def.content | should -be "file content"

# passthru other params
# decoding BASE64 string
$persist_def = persist_def_obj $obj.persist_file[5]
$persist_def.source | should -be "foo"
$persist_def.target | should -be "foo"
$persist_def.content | should -be "file`r`ncontent"

# passthru other params
$persist_def = persist_def_obj $obj.persist_file[6]
$persist_def.source | should -be "foo"
$persist_def.target | should -be "foo"
$persist_def.content | should -be "file`r`ncontent"
$persist_def.method | should -be "update"
$persist_def.encoding | should -be "UTF8"
}
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/persist/persist-object.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@
"content"
],
"glue": " "
}, {
"name": "foo",
"content": [
"ZmlsZQ0K",
"Y29udGVudA=="
],
"base64": true
}, {
"name": "foo",
"content": [
Expand Down

0 comments on commit 667e773

Please sign in to comment.