Skip to content

Conversation

@austoonz
Copy link
Owner

Summary

Adds the -Encoding parameter to ConvertFrom-MemoryStreamToString and ConvertFrom-MemoryStreamToSecureString functions, resolving the inconsistency where these functions hardcoded UTF-8 encoding while other similar functions in the module support encoding selection.

Changes

New Features

  • Added -Encoding parameter to ConvertFrom-MemoryStreamToString
  • Added -Encoding parameter to ConvertFrom-MemoryStreamToSecureString
  • Both default to UTF8 for backward compatibility
  • Supported encodings: ASCII, BigEndianUnicode, Default, Unicode, UTF32, UTF8

Fixed

  • ConvertFrom-MemoryStream now correctly passes -Encoding to ConvertFrom-MemoryStreamToString for consistent behavior across the module

Tests

  • Added encoding tests for both functions covering all supported encodings
  • Updated ConvertFrom-MemoryStream tests to create streams with correct encoding

Documentation

  • Updated function documentation with new parameter
  • Updated CHANGELOG

Example

# Create a MemoryStream with UTF-16 encoded content
$bytes = [System.Text.Encoding]::Unicode.GetBytes("Hello World")
$stream = [System.IO.MemoryStream]::new($bytes)

# Now works correctly with -Encoding parameter
$stream | ConvertFrom-MemoryStreamToString -Encoding Unicode
# Output: "Hello World"

Closes #21

…21)

- Add -Encoding parameter to ConvertFrom-MemoryStreamToString
- Add -Encoding parameter to ConvertFrom-MemoryStreamToSecureString
- Pass -Encoding through in ConvertFrom-MemoryStream for consistency
- Update tests to use correct encoding when creating streams
- Update documentation and CHANGELOG
@austoonz austoonz merged commit 59ec3a0 into main Jan 30, 2026
23 checks passed
@austoonz austoonz deleted the feature/issue-21-memorystream-encoding branch January 30, 2026 01:43
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.

Add -Encoding parameter to ConvertFrom-MemoryStreamToString and ConvertFrom-MemoryStreamToSecureString

2 participants