mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-17 12:22:34 +03:00
refactor(video): derive the JPEG frame pattern from the exported prefix
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
export const JPEG_FRAME_DATA_URI_PREFIX = "data:image/jpeg;base64,";
|
||||
|
||||
const JPEG_FRAME_DATA_URI_PATTERN = /^data:image\/jpeg;base64,([A-Za-z0-9+/=]+)$/i;
|
||||
// Derived from the exported prefix so the two can never drift apart.
|
||||
const JPEG_FRAME_DATA_URI_PATTERN = new RegExp(
|
||||
`^${JPEG_FRAME_DATA_URI_PREFIX.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&")}([A-Za-z0-9+/=]+)$`,
|
||||
"i"
|
||||
);
|
||||
|
||||
function matchJpegFrame(dataUri: string): string {
|
||||
const match = JPEG_FRAME_DATA_URI_PATTERN.exec(dataUri);
|
||||
@@ -8,7 +12,10 @@ function matchJpegFrame(dataUri: string): string {
|
||||
return match[1];
|
||||
}
|
||||
|
||||
/** Throws on any non-JPEG or base64-invalid input; the single frame decode used by every video module. */
|
||||
/**
|
||||
* Throws on any non-JPEG or base64-invalid input; the single frame decode used by every
|
||||
* video module.
|
||||
*/
|
||||
export function decodeJpegFrameDataUri(dataUri: string): Buffer {
|
||||
return Buffer.from(matchJpegFrame(dataUri), "base64");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user