@wordpress/upload-media
Version:
Core media upload logic.
87 lines • 3.13 kB
TypeScript
/**
* Converts a Blob to a File with a default name like "image.png".
*
* If it is already a File object, it is returned unchanged.
*
* Handles cross-realm File objects (e.g., from iframes) that have a `name`
* property but fail `instanceof File` checks because the File constructor
* differs between browsing contexts.
*
* @param fileOrBlob Blob object.
* @return File object.
*/
export declare function convertBlobToFile(fileOrBlob: Blob | File): File;
/**
* Renames a given file and returns a new file.
*
* Copies over the last modified time.
*
* @param file File object.
* @param name File name.
* @return Renamed file object.
*/
export declare function renameFile(file: File, name: string): File;
/**
* Clones a given file object.
*
* @param file File object.
* @return New file object.
*/
export declare function cloneFile(file: File): File;
/**
* Returns the file extension from a given file name or URL.
*
* @param file File URL.
* @return File extension or null if it does not have one.
*/
export declare function getFileExtension(file: string): string | null;
/**
* Returns file basename without extension.
*
* For example, turns "my-awesome-file.jpeg" into "my-awesome-file".
*
* @param name File name.
* @return File basename.
*/
export declare function getFileBasename(name: string): string;
/**
* Returns the file name including extension from a URL.
*
* @param url File URL.
* @return File name.
*/
export declare function getFileNameFromUrl(url: string): string;
/**
* Detects whether a file buffer contains an animated GIF.
*
* Performs binary analysis of the GIF file structure:
* 1. Checks for the GIF magic bytes ("GIF8")
* 2. Counts frame blocks by scanning for Graphic Control Extension headers
* (Block Terminator 0x00 + Extension Introducer 0x21 + Graphic Control Label 0xF9)
* 3. Returns true if more than 1 frame is found
*
* This is a deliberately cheap heuristic, not a full GIF parser. It scans
* the raw bytes for the Graphic Control Extension marker rather than walking
* the block structure, which has two known limitations:
*
* - False positives: the 0x00 0x21 0xF9 byte sequence can occur coincidentally
* inside LZW-compressed image data, so a single-frame GIF may be reported as
* animated.
* - False negatives: Graphic Control Extension blocks are optional per the GIF
* spec, so an animated GIF that omits them is reported as static.
*
* Both outcomes are non-destructive: the worker's ImageDecoder frame count is
* the authoritative source, so a misdetected static GIF still encodes to an
* accurate (1-frame) video, and a misdetected animated GIF simply falls back
* to the normal image upload pipeline. A full structural parse is intentionally
* avoided here to keep this off the hot path of every GIF upload.
*
* Based on the GIF specification:
*
* @see http://www.matthewflickinger.com/lab/whatsinagif/
*
* @param buffer File ArrayBuffer.
* @return Whether the buffer contains an animated GIF.
*/
export declare function isAnimatedGif(buffer: ArrayBuffer): boolean;
//# sourceMappingURL=utils.d.ts.map