base85Encode encodes src in Base85, writing the result to dst. It uses the alphabet defined by base85.c in the Git source tree.
(dst, src []byte)
| 54 | // base85Encode encodes src in Base85, writing the result to dst. It uses the |
| 55 | // alphabet defined by base85.c in the Git source tree. |
| 56 | func base85Encode(dst, src []byte) { |
| 57 | var di, si int |
| 58 | |
| 59 | encode := func(v uint32) { |
| 60 | dst[di+0] = b85Alpha[(v/(85*85*85*85))%85] |
| 61 | dst[di+1] = b85Alpha[(v/(85*85*85))%85] |
| 62 | dst[di+2] = b85Alpha[(v/(85*85))%85] |
| 63 | dst[di+3] = b85Alpha[(v/85)%85] |
| 64 | dst[di+4] = b85Alpha[v%85] |
| 65 | } |
| 66 | |
| 67 | n := (len(src) / 4) * 4 |
| 68 | for si < n { |
| 69 | encode(uint32(src[si+0])<<24 | uint32(src[si+1])<<16 | uint32(src[si+2])<<8 | uint32(src[si+3])) |
| 70 | si += 4 |
| 71 | di += 5 |
| 72 | } |
| 73 | |
| 74 | var v uint32 |
| 75 | switch len(src) - si { |
| 76 | case 3: |
| 77 | v |= uint32(src[si+2]) << 8 |
| 78 | fallthrough |
| 79 | case 2: |
| 80 | v |= uint32(src[si+1]) << 16 |
| 81 | fallthrough |
| 82 | case 1: |
| 83 | v |= uint32(src[si+0]) << 24 |
| 84 | encode(v) |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | // base85Len returns the length of n bytes of Base85 encoded data. |
| 89 | func base85Len(n int) int { |
no outgoing calls