Skip to content

Commit

Permalink
change chunk size to 4 bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
quackduck committed Mar 6, 2023
1 parent 2d86734 commit a0ca5b9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ RRD RBO RKD M DRBU MBRRRKD RDOR

You can also use emojis:
```shell
$ echo -n uwonsmth | aces 🥇🥈🥉
🥇🥉🥇🥇🥉🥈🥇🥈🥈🥉🥈🥉🥈🥈🥈🥉🥇🥈🥇🥈🥇🥇🥇🥈🥉🥈🥈🥈🥉🥉🥉🥇🥈🥈🥉🥉🥉🥉🥇🥇🥈
$ echo -n yay | aces 🥇🥈🥉
🥇🥈🥉🥇🥉🥇🥉🥉🥇🥉🥉🥇🥈🥇🥉🥇🥉🥉🥇🥉🥇🥈🥇
```

With Aces, you can see the actual 0s and 1s of files:
Expand Down Expand Up @@ -80,7 +80,7 @@ Examples:
echo Calculus | aces 01 # what's stuff in binary?
echo Aces™ | base64 | aces -d
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/ # even decode base64
echo -n uwonsmth | aces 🥇🥈🥉 # emojis work too!
echo -n yay | aces 🥇🥈🥉 # emojis work too!
Set the encoding/decoding buffer size with --bufsize <size> (default 16KiB).

File issues, contribute or star at github.com/quackduck/aces
Expand Down
8 changes: 4 additions & 4 deletions aces.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const defaultBufSize = 16 * 1024

// size of the byte chunk whose base is converted at a time when the length of the character
// set is not a power of 2. See NewCoding for more detail.
const defaultNonPow2ByteChunkSize = 8
const defaultNonPow2ByteChunkSize = 4

// sliceByteLen slices the byte b such that the result has length len and starting bit start
func sliceByteLen(b byte, start uint8, len uint8) byte {
Expand Down Expand Up @@ -177,7 +177,7 @@ type Coding interface {
//
// This is because most encoders interpret data as a number and use a base conversion algorithm to convert it to the
// character set. For non-power-of-2 charsets, this requires all data to be read before encoding, which is not possible
// with streams. To enable stream encoding for non-power-of-2 charsets, Aces converts a default of 8 bytes (adjustable
// with streams. To enable stream encoding for non-power-of-2 charsets, Aces converts a default of 4 bytes (adjustable
// with Coding.SetByteChunkSize) of data at a time, which is not the same as converting the base of the entire data.
func NewCoding(charset []rune) (Coding, error) {
seen := make(map[rune]bool)
Expand Down Expand Up @@ -329,9 +329,9 @@ func (c *anyCoding) Encode(dst io.Writer, src io.Reader) error {

var resultBuf = make([]rune, 0, 64)

func encodeByteChunk(set []rune, octet []byte, rPerChunk int) []rune {
func encodeByteChunk(set []rune, chunk []byte, rPerChunk int) []rune {
resultBuf = resultBuf[:0]
i := bytesToInt(octet)
i := bytesToInt(chunk)
resultBuf = toBase(i, resultBuf, set)
//return append([]rune(strings.Repeat(string(set[0]), rPerChunk-len(resultBuf))), resultBuf...)
for len(resultBuf) < rPerChunk {
Expand Down
2 changes: 1 addition & 1 deletion cmd/aces/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Examples:
echo Calculus | aces 01 # what's stuff in binary?
echo Aces™ | base64 | aces -d
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/ # even decode base64
echo -n uwonsmth | aces 🥇🥈🥉 # emojis work too!
echo -n yay | aces 🥇🥈🥉 # emojis work too!
Set the encoding/decoding buffer size with --bufsize <size> (default 16KiB).
File issues, contribute or star at github.com/quackduck/aces`
Expand Down

0 comments on commit a0ca5b9

Please sign in to comment.