@ -535,17 +535,17 @@ assert.equal('TWFu', (Buffer.from('Man')).toString('base64'));
{
{
// big example
// big example
const quote = 'Man is distinguished, not only by his reason, but by this ' +
const quote = 'Man is distinguished, not only by his reason, but by this ' +
'singular passion from other animals, which is a lust ' +
'singular passion from other animals, which is a lust ' +
'of the mind, that by a perseverance of delight in the ' +
'of the mind, that by a perseverance of delight in the ' +
'continued and indefatigable generation of knowledge, exceeds ' +
'continued and indefatigable generation of knowledge, ' +
'the short vehemence of any carnal pleasure.' ;
'exceeds the short vehemence of any carnal pleasure.' ;
const expected = 'TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb' +
const expected = 'TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb' +
'24sIGJ1dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBh ' +
'24sIGJ1dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlci' +
'bmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnk ' +
'Bh bmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQ' +
'gYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGludWVkIG ' +
'gYnk gYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu' +
'FuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBle ' +
'dWVkIG FuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZ' +
'GNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVh ' +
'GdlLCBle GNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm' +
'c3VyZS4=' ;
'5hbCBwbGVh c3VyZS4=' ;
assert . equal ( expected , ( Buffer . from ( quote ) ) . toString ( 'base64' ) ) ;
assert . equal ( expected , ( Buffer . from ( quote ) ) . toString ( 'base64' ) ) ;
let b = Buffer . allocUnsafe ( 1024 ) ;
let b = Buffer . allocUnsafe ( 1024 ) ;
@ -555,11 +555,11 @@ assert.equal('TWFu', (Buffer.from('Man')).toString('base64'));
// check that the base64 decoder ignores whitespace
// check that the base64 decoder ignores whitespace
const expectedWhite = expected . slice ( 0 , 60 ) + ' \n' +
const expectedWhite = expected . slice ( 0 , 60 ) + ' \n' +
expected . slice ( 60 , 120 ) + ' \n' +
expected . slice ( 60 , 120 ) + ' \n' +
expected . slice ( 120 , 180 ) + ' \n' +
expected . slice ( 120 , 180 ) + ' \n' +
expected . slice ( 180 , 240 ) + ' \n' +
expected . slice ( 180 , 240 ) + ' \n' +
expected . slice ( 240 , 300 ) + '\n' +
expected . slice ( 240 , 300 ) + '\n' +
expected . slice ( 300 , 360 ) + '\n' ;
expected . slice ( 300 , 360 ) + '\n' ;
b = Buffer . allocUnsafe ( 1024 ) ;
b = Buffer . allocUnsafe ( 1024 ) ;
bytesWritten = b . write ( expectedWhite , 0 , 'base64' ) ;
bytesWritten = b . write ( expectedWhite , 0 , 'base64' ) ;
assert . equal ( quote . length , bytesWritten ) ;
assert . equal ( quote . length , bytesWritten ) ;
@ -573,11 +573,11 @@ assert.equal('TWFu', (Buffer.from('Man')).toString('base64'));
// check that the base64 decoder ignores illegal chars
// check that the base64 decoder ignores illegal chars
const expectedIllegal = expected . slice ( 0 , 60 ) + ' \x80' +
const expectedIllegal = expected . slice ( 0 , 60 ) + ' \x80' +
expected . slice ( 60 , 120 ) + ' \xff' +
expected . slice ( 60 , 120 ) + ' \xff' +
expected . slice ( 120 , 180 ) + ' \x00' +
expected . slice ( 120 , 180 ) + ' \x00' +
expected . slice ( 180 , 240 ) + ' \x98' +
expected . slice ( 180 , 240 ) + ' \x98' +
expected . slice ( 240 , 300 ) + '\x03' +
expected . slice ( 240 , 300 ) + '\x03' +
expected . slice ( 300 , 360 ) ;
expected . slice ( 300 , 360 ) ;
b = Buffer . from ( expectedIllegal , 'base64' ) ;
b = Buffer . from ( expectedIllegal , 'base64' ) ;
assert . equal ( quote . length , b . length ) ;
assert . equal ( quote . length , b . length ) ;
assert . equal ( quote , b . toString ( 'ascii' , 0 , quote . length ) ) ;
assert . equal ( quote , b . toString ( 'ascii' , 0 , quote . length ) ) ;