Skip to content

Add AsOneString parameter to ConvertTo-Base64 for single string encoding#8

Closed
Copilot wants to merge 3 commits intomainfrom
copilot/fix-7
Closed

Add AsOneString parameter to ConvertTo-Base64 for single string encoding#8
Copilot wants to merge 3 commits intomainfrom
copilot/fix-7

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 28, 2025

Changes

This PR adds a new -AsOneString switch parameter to the ConvertTo-Base64 function that allows users to encode multiple input lines as a single base64 string, similar to how the Linux base64 utility works.

Before:

Get-Content -Path file.txt | ConvertTo-Base64
# Results in multiple base64 strings (one per line in the file)
TGluZSAx
TGluZSAy
TGluZSAz

After:

Get-Content -Path file.txt | ConvertTo-Base64 -AsOneString
# Results in a single base64 string with all lines joined by newlines
TGluZSAxCkxpbmUgMgpMaW5lIDM=

Implementation Details

  • Added -AsOneString switch parameter to allow joining inputs with newlines
  • Used begin/process/end blocks to accumulate input when the switch is used
  • Updated documentation with new examples showing the parameter usage
  • Added tests to verify the functionality

Example using a file:

$content = Get-Content -Path test.txt
# Without -AsOneString (each line encoded separately):
$content | ConvertTo-Base64
# With -AsOneString (all joined with newlines and encoded as one):
$content | ConvertTo-Base64 -AsOneString

This matches the behavior requested in the issue where the user wanted to encode file content as a single base64 string, similar to the Linux base64 utility.

Fixes #7.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits May 28, 2025 01:53
Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com>
Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com>
Copilot AI changed the title [WIP] 🌞 [Other]: Opinion about 2.0.2 Add AsOneString parameter to ConvertTo-Base64 for single string encoding May 28, 2025
@MariusStorhaug Marius Storhaug (MariusStorhaug) deleted the copilot/fix-7 branch May 28, 2025 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🌞 [Other]: Opinion about 2.0.2

2 participants