Browse Source

Merge pull request #3995 from TiVo/fix-base64

optimisation to Base64 encoding
Nicolas Cannasse 10 years ago
parent
commit
6c4c98eb5c
1 changed files with 6 additions and 1 deletions
  1. 6 1
      std/haxe/crypto/Base64.hx

+ 6 - 1
std/haxe/crypto/Base64.hx

@@ -32,8 +32,13 @@ class Base64 {
 	public static function encode( bytes : haxe.io.Bytes, complement = true ) : String {
 		var str = new BaseCode(BYTES).encodeBytes(bytes).toString();
 		if( complement )
-			for( i in 0...(3-(bytes.length*4)%3)%3 )
+			switch (bytes.length % 3) {
+			case 1:
+				str += "==";
+			case 2:
 				str += "=";
+			default:
+			}
 		return str;
 	}