Data URL Parser

Parse a data URL into its media-type declaration, Base64 flag, and decoded byte sequence without guessing a text encoding.

Description

A data URL carries a media-type declaration and embedded bytes, optionally encoded as Base64.

A data URL carries a media-type declaration and embedded bytes, optionally encoded as Base64. Returning bytes avoids guessing a text encoding from a declaration.1

Parse a data URL into its media-type declaration, Base64 flag, and decoded byte sequence without guessing a text encoding.

When to use Data URL Parser

Use this tool to parse a data URL into its media-type declaration, Base64 flag, and decoded byte sequence without guessing a text encoding.

Choose the URL, decoded source text, header value or explicit byte list requested by this tool. Paste the complete relevant input and follow its parsing and encoding conventions.

How to use Data URL Parser and understand its results

  1. Choose the URL, decoded source text, header value or explicit byte list requested by this tool. Paste the complete relevant input and follow its parsing and encoding conventions.
  2. Enter url using the field table and calculation rules, then run the tool.
  3. Read mediaType, base64, bytes. The explanation below defines the units, signs, ordering and any flags or placeholder values.
  4. If the tool reports an input issue, correct the values and run it again. Apply the stated assumptions when interpreting a successfully returned result.
Input fieldMeaningValue type; see rules belowRequirement
urlAbsolute data URL.string; maximum length: 1000000Required

Paste an absolute data URL containing a comma. Parse the URL, split the first pathname comma, recognize a final case-insensitive ;base64 and retain query text as payload while excluding the fragment. Percent escapes become bytes and unescaped characters become UTF-8 bytes. Base64 whitespace is removed and missing final padding is supplied where possible. Return declaration, encoding flag and decoded bytes.

payloadBytes=percentDecodeBytes(payload); if base64: decodeBase64(payloadBytes)

Units, indexing, boundary conditions and exceptional cases are defined in the calculation rules above.

Output fieldMeaningValue type
mediaTypeDeclared media type or RFC 2397 default.string; maximum length: 1000000
base64Whether Base64 encoding was declared.boolean
bytesDecoded payload bytes.list of integer; minimum: 0; maximum: 255; minimum entries: 0; maximum entries: 1000000
json
{
  "input": {
    "url": "data:text/plain;base64,SGVsbG8="
  },
  "output": {
    "mediaType": "text/plain",
    "base64": true,
    "bytes": [
      72,
      101,
      108,
      108,
      111
    ]
  }
}

Limitations and assumptions

Empty metadata defaults to text/plain;charset=US-ASCII; leading parameter metadata gains text/plain. Other declarations are retained without MIME validation. Invalid Base64 is an error, and bytes are not interpreted as text or executed.

Numeric inputs must be finite. Follow the calculation-specific rules for overflow, underflow and exceptional cases. Extremely large text inputs are rejected. Missing required fields, extra fields, wrong value types and violations of the calculation rules are input errors. A successfully returned false flag is an evaluated outcome; its meaning is explained above.

Alternative or Complementary methods

Use URL Is Data: Check whether an absolute WHATWG URL uses the data scheme. For a complementary task, use Subresource Integrity Hash Generator: Hash explicit UTF-8 text with SHA-256, SHA-384, or SHA-512 and emit Base64 Subresource Integrity metadata.

References

  1. Data URL Parser — tool.io

Similar or alternative tools

Don't forget to set a bookmark for tool.io!
Privacy | Imprint | Cookies