How to convert string to binary in javascript?

#1

Is there a platform API that I can use to convert a string to binary data in javascript? I want to use the result to pass into Tag.deployMetadataFiles()

#3

Binary values can be encoded as strings using “base-64” (which is how binary data is serialized). If you have a base-64 string in JavaScript, you can convert it to a JavaScript ArrayBuffer with C3.util.b64decode (and the reverse with C3.util.b64encode).

1 Like
#4

There is also a type in C3 called Base64 that has the following apis:

/**
 * Utility type for Base64 encoding/decoding binary data to/from a string
 */
type Base64 {
  /**
   * Convert from bytes to base64 string
   */
  encode: inline function(value: !binary): !string

  /**
   * Convert from base64 string to bytes
   */
  decode: inline function(value: !string): !binary

  /**
   * Encodes string into a base64 string using the named charset
   */
  encodeString: inline function(value: !string, charset: string): !string

  /**
   * decodes a base string using named charset into a string
   */
  decodeString: inline function(value: !string, charset: string): !string

  /**
   * Encodes a long number into a base64 string
   */
  encodeLong: inline function (value: !long int): !string

  /**
   * decodes a base64 string into a long number
   */
  decodeLong: inline function (value: !string): !long int
}