@@ -291,13 +291,13 @@ func (c *anyCoding) SetByteChunkSize(size int) {
291291func (c * anyCoding ) SetBufferSize (bufSize int ) { c .bufSize = bufSize }
292292
293293func (c * anyCoding ) Encode (dst io.Writer , src io.Reader ) error {
294- //br := bufio.NewReaderSize(src, c.bufSize)
295294 result := make ([]rune , 0 , c .bufSize )
296295 buf := make ([]byte , c .chunkSize )
297- endWrite := func (n int ) error { // endWrite takes the number of bytes that were just read, encodes it and writes to dst.
298- result = append (result , encodeByteChunk (c .charset , buf , c .rPerChunk )... )
299- result = append (result , toBase (bytesToInt ([]byte {byte (n )}), make ([]rune , 0 , 8 ), c .charset )... )
300- _ , err := dst .Write ([]byte (string (result )))
296+ endWrite := func (n int ) error { // endWrite takes the number of bytes that were just read, encodes it and writes to dst. This allows the decoder to trim the last chunk down to the right size.
297+ _ , err := dst .Write ([]byte (string (append (append (
298+ result ,
299+ encodeByteChunk (c .charset , buf , c .rPerChunk )... ),
300+ toBase (bytesToInt ([]byte {byte (n )}), make ([]rune , 0 , 8 ), c .charset )... ))))
301301 return err
302302 }
303303 for {
@@ -309,7 +309,6 @@ func (c *anyCoding) Encode(dst io.Writer, src io.Reader) error {
309309 return err
310310 }
311311 if err == io .ErrUnexpectedEOF { // end of data, not a multiple of chunk size.
312- // encode how many bytes of this chunk to keep
313312 if err = endWrite (n ); err != nil {
314313 return err
315314 }
@@ -349,8 +348,6 @@ func decodeToByteChunk(set []rune, runes []rune, chunkSize int) ([]byte, error)
349348 if err != nil {
350349 return nil , err
351350 }
352- //println(num.String())
353- //fmt.Println(num.String())
354351 return num .FillBytes (make ([]byte , chunkSize )), nil
355352}
356353
0 commit comments