pols-utils - v5.3.11
    Preparing search index...

    Class PBase64

    Manage a Base64 string.

    import { PBase64 } from 'pols-utils'
    const mybase64 = PBase64.fromBase64String('data:image/png;base64,examplecode=')
    console.log(mybase64.mimeType) // 'image/png'
    console.log(mybase64.size) // Size of image in bytes
    console.log(mybase64.content) // 'examplecode'
    import { PBase64 } from 'pols-utils'
    PBase64.fromFile('file/location.any').then(mybase64 => {
    console.log(mybase64.mimeType) // Mime type based in the file name. 'application/octet-stream' by default.
    console.log(mybase64.size) // Size of file in bytes
    console.log(mybase64.content) // File content at Base64 string
    })
    Index

    Constructors

    Properties

    mimeType: string = DEFAULT_MIME_TYPE

    Get the mime type if the value. If it was set from a file content, the mimeType prop get 'application/octet-stream' value.

    Accessors

    • get content(): string

      Get the Base64 string. It represents only the content. Data URI will be ignored.

      Returns string

    • get isInvalid(): boolean

      Get if the content is invalid.

      Returns boolean

    • get size(): number

      Represent the size in bytes of the buffer resulting from decoding the Base64 string. It correspond to the original contentsize before encoding.

      Returns number

    Methods

    • Convert the content to a Buffer instance.

      Returns Buffer

    • Convert the content to a decoded string.

      Parameters

      • encode: BufferEncoding = 'utf-8'

      Returns string

    • Set the content from a Base64 string. The mime type extract from the data URI. If it not exists, the mime type will be 'application/octet-stream'.

      Parameters

      • value: string

        The Base64 string.

      Returns PBase64

    • Set the content from a file. Extract the content and encode to Base64.

      Parameters

      • fileLocation: string

        File location.

      Returns Promise<PBase64>