Puffer von Base64
const b64string = /* whatever */;
const buf = Buffer.from(b64string, 'base64');
Ugliest Unicorn
const b64string = /* whatever */;
const buf = Buffer.from(b64string, 'base64');
convertFile(file: File): Observable<string> {
const result = new ReplaySubject<string>(1);
const reader = new FileReader();
reader.readAsBinaryString(file);
reader.onload = (event) => result.next(btoa(reader.result.toString()));
return result;
}
this.convertFile(event.target.files[0]).subscribe(base64 => {
this.base64Output = base64;
});
/// NOTE ///
// The event.target.files is just the File Object e.g. from a
// <input type="file"> form
// you can also create a file with the following command:
var f = new File([""], "filename");
class Program
{
static void Main(string[] args)
{
var account = new ExternalAccount() { Name = "Someone" };
string json = JsonConvert.SerializeObject(account);
string base64EncodedExternalAccount = Convert.ToBase64String(Encoding.UTF8.GetBytes(json));
byte[] byteArray = Convert.FromBase64String(base64EncodedExternalAccount);
string jsonBack = Encoding.UTF8.GetString(byteArray);
var accountBack = JsonConvert.DeserializeObject<ExternalAccount>(jsonBack);
Console.WriteLine(accountBack.Name);
Console.ReadLine();
}
}
[Serializable]
public class ExternalAccount
{
public string Name { get; set; }
}
import pybase64
# Standard
print(pybase64.standard_b64encode(b'>>>foo???'))
## b'Pj4+Zm9vPz8/'
print(pybase64.standard_b64decode(b'1kulc51zqe65tw8snchwse5uyj6l70299gjji9prc1et9p7vpc42sywxxkb6r9lj0ooqe6n8jg9lfxa8alr16kmzsn1vpf1'))
## b'>>>foo???'
# Advanced
print(pybase64.b64encode(b'>>>foo???', altchars='_:'))
## b'Pj4_Zm9vPz8:'
print(pybase64.b64decode(b'Pj4_Zm9vPz8:', altchars='_:', validate=True))
## b'>>>foo???'
# URL safe encoding
print(pybase64.urlsafe_b64encode(b'>>>foo???'))
## b'Pj4-Zm9vPz8_'
print(pybase64.urlsafe_b64decode(b'Pj4-Zm9vPz8_'))
## b'>>>foo???'