Repository navigation
Add the 'u' (uuencode) pack/unpack directive - #446
Merged
Merged
Conversation
Array#pack("u") and String#unpack("u") raised "unknown directive 'u'". They now
implement uuencoding and uudecoding:
- pack("u") emits one line per chunk: a length character (data-byte count),
then the bytes in groups of three as four 6-bit characters (value 0 as a
backtick, others as value+0x20), then a newline. The count modifier sets the
bytes-per-line — '*', 0, 1, 2, or none means 45; otherwise it is rounded
down to a multiple of three. An empty input yields an empty string, a
non-String element raises TypeError, and the result is US-ASCII.
- unpack("u") decodes the whole input across newline-separated lines back to a
single BINARY string, ignoring the count/'*' modifier; each character
contributes (c-0x20)&0x3f and a CR?LF terminates a line. Decoding stops at
the first character that cannot begin a line.
Verified against ruby 4.0.6. Full package coverage stays at 100.0%. Zero-
regression rubyspec sweep; core/array/pack/u_spec 17 -> 35 and
core/string/unpack/u_spec 17 -> 25 (with the remaining failures in both files
being pre-existing 'U'-directive and shared-mock issues, unrelated to 'u'). Two
shared examples in pack/a_spec and pack/z_spec also start passing now that 'u'
is a recognized directive.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Array#pack("u")andString#unpack("u")raisedunknown directive 'u'. Theynow implement uuencoding and uudecoding:
pack("u")emits one line per chunk: a length character (data-byte count),then the bytes in groups of three as four 6-bit characters (value 0 as a
backtick, others as
value+0x20), then a newline. The count modifier sets thebytes-per-line —
*,0,1,2, or none means 45; otherwise it is roundeddown to a multiple of three. An empty input yields an empty string, a
non-String element raises
TypeError, and the result is US-ASCII.unpack("u")decodes the whole input across newline-separated lines back to asingle BINARY string, ignoring the count/
*modifier; each charactercontributes
(c-0x20)&0x3fand a CR?LF terminates a line. Decoding stops atthe first character that cannot begin a line.
Verified against ruby 4.0.6. Full package coverage stays at 100.0%.
Zero-regression rubyspec sweep;
core/array/pack/u_spec17 → 35 andcore/string/unpack/u_spec17 → 25 (the remaining failures in both files arepre-existing
U-directive and shared-mock issues, unrelated tou). Two sharedexamples in
pack/a_specandpack/z_specalso start passing now thatuis arecognized directive.
🤖 Generated with Claude Code