Skip to content

Commit b5d433b

Browse files
committed
cleanup
1 parent a9bafb9 commit b5d433b

File tree

1 file changed

+6
-47
lines changed

1 file changed

+6
-47
lines changed

aces.go

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -298,37 +298,17 @@ func (c *anyCoding) Encode(dst io.Writer, src io.Reader) error {
298298
n, err := io.ReadFull(src, buf)
299299
if err != nil && err != io.ErrUnexpectedEOF {
300300
if err == io.EOF {
301-
//println("got eof")
302-
r := toBase(
303-
bytesToInt([]byte{byte(c.chunkSize)}),
304-
make([]rune, 0, 8),
305-
c.charset,
306-
)
307-
308-
//encoded nunmber must be less than chunksize long
309-
//println(string(r), n, fmt.Sprint([]byte{byte(n)}), bytesToInt([]byte{byte(n)}).String(), string(c.charset))
310-
//result = append(result, encodeByteChunk(c.charset, buf, c.rPerChunk)...)
301+
r := toBase(bytesToInt([]byte{byte(c.chunkSize)}), make([]rune, 0, 8), c.charset)
311302
result = append(result, r...)
312303
_, err = dst.Write([]byte(string(result)))
313304
}
314305
return err
315306
}
316-
if err == io.ErrUnexpectedEOF { // end of data, not a multiple of chunk size. TODO: somehow encode how many null bytes to cut off when decoding
317-
// buffer is going to have zeros at the end
318-
//buf = append(buf[:n], make([]byte, c.chunkSize-n)...)
319-
//buf = append(buf, byte(c.chunkSize-n)) // number of zeros to cut off
320-
//var b = // just one byte encoded
321-
// r is that one byte encoded
322-
//println("got unexpected eof")
323-
r := toBase(
324-
bytesToInt([]byte{byte(n)}),
325-
make([]rune, 0, 8),
326-
c.charset,
327-
)
328-
329-
//encoded nunmber must be less than chunksize long
330-
//println(string(r), n, fmt.Sprint([]byte{byte(n)}), bytesToInt([]byte{byte(n)}).String(), string(c.charset))
307+
if err == io.ErrUnexpectedEOF { // end of data, not a multiple of chunk size.
308+
// encode how many bytes of this chunk to keep
331309
result = append(result, encodeByteChunk(c.charset, buf, c.rPerChunk)...)
310+
r := toBase(bytesToInt([]byte{byte(n)}), make([]rune, 0, 8), c.charset)
311+
//encoded number must be less than chunksize long
332312
result = append(result, r...)
333313
_, err = dst.Write([]byte(string(result)))
334314
if err != nil {
@@ -338,7 +318,6 @@ func (c *anyCoding) Encode(dst io.Writer, src io.Reader) error {
338318
}
339319

340320
result = append(result, encodeByteChunk(c.charset, buf, c.rPerChunk)...)
341-
//println(fmt.Sprint(result))
342321

343322
if len(result)+(8*int(c.chunkSize)) > cap(result) { // (8*c.chunkSize) is the max size of the result (considering worst case: charset has length 2)
344323
_, err = dst.Write([]byte(string(result)))
@@ -385,40 +364,22 @@ func (c *anyCoding) Decode(dst io.Writer, src io.Reader) error {
385364
var currChunk []byte
386365
var lastChunk []byte
387366
for {
388-
//println("result size", len(result))
389367
for i := range buf { // read a chunk
390368
buf[i], _, err = br.ReadRune()
391369
if err != nil {
392370
if err == io.EOF {
393-
//println("decoding. buf is", string(buf[:i-1]), fmt.Sprint(buf[:i-1]), "currchunk size is", len(currChunk))
394371
toKeep := int64(c.chunkSize)
395372
if i > 0 { // we_did read some data, right?
396-
397373
// the current value of buf decoded will be the length of the previous chunk to keep.
398-
399374
bigNum, err := fromBase(buf[:i-1], c.charset)
400375
if err != nil {
401376
return err
402377
}
403378
toKeep = bigNum.Int64()
404-
//println(toKeep)
405-
406-
// // now check the last byte (which encodes how many zeros to cut off)
407-
// err = br.UnreadByte()
408-
// if err != nil {
409-
// return err
410-
// }
411-
// b, err := br.ReadByte()
412-
// if err != nil {
413-
// return err
414-
// }
415-
// result = result[:len(buf)-int(b)]
416379
}
417-
//println(toKeep, c.chunkSize)
418380
currChunk = currChunk[:toKeep]
419381
result = append(result, currChunk...)
420382
_, err = dst.Write(result)
421-
//println("YAHOOO!!")
422383
}
423384
return err
424385
}
@@ -432,9 +393,7 @@ func (c *anyCoding) Decode(dst io.Writer, src io.Reader) error {
432393
return err
433394
}
434395
result = append(result, lastChunk...)
435-
//println(len(result))
436-
lastChunk = currChunk
437-
//copy(lastChunk, currChunk) // this system is here because the current chunk may get modified in the next round when there's an EOF
396+
lastChunk = currChunk // this system is here because the current chunk may get modified in the next round when there's an EOF
438397

439398
if len(result)+c.chunkSize > cap(result) {
440399
_, err = dst.Write(result)

0 commit comments

Comments
 (0)