This commit is contained in:
Manav Rathi 2024-04-17 11:55:07 +05:30
parent 637d830f19
commit 2d5ab044ee
No known key found for this signature in database
2 changed files with 25 additions and 10 deletions

View file

@ -34,16 +34,6 @@ export const decodeLivePhoto = async (file: EnteFile, zipBlob: Blob) => {
return livePhoto;
};
/**
* Return a binary serialized representation of a live photo.
*
* This function takes the (in-memory) image and video data from the
* {@link livePhoto} object, writes them to a zip file (using the respective
* filenames), and returns the {@link Uint8Array} that represent the bytes of
* this zip file.
*
* @param livePhoto The in-mem photo to serialized.
*/
export const encodeLivePhoto = async (livePhoto: LivePhoto) => {
const zip = new JSZip();
zip.file(

View file

@ -20,6 +20,21 @@ export function getFileExtensionWithDot(filename: string) {
else return filename.slice(lastDotPosition);
}
/**
* Convert a binary serialized representation of a live photo to an in-memory
* {@link LivePhoto}.
*
* A live photo is a zip file containing two files - an image and a video. This
* functions reads that zip file (blob), and return separate bytes (and
* filenames) for the image and video parts.
*
* @param fileName The name of the overall live photo. Both the image and video
* parts of the decompressed live photo use this as their name, combined with
* their original extensions.
*
* @param zipBlob A blob contained the zipped data (i.e. the binary serialized
* live photo).
*/
export const decodeLivePhoto = async (fileName: string, zipBlob: Blob) => {
const [name] = nameAndExtension(fileName);
const zip = await JSZip.loadAsync(zipBlob, { createFolders: true });
@ -39,6 +54,16 @@ export const decodeLivePhoto = async (fileName: string, zipBlob: Blob) => {
return livePhoto;
};
/**
* Return a binary serialized representation of a live photo.
*
* This function takes the (in-memory) image and video data from the
* {@link livePhoto} object, writes them to a zip file (using the respective
* filenames), and returns the {@link Uint8Array} that represent the bytes of
* this zip file.
*
* @param livePhoto The in-mem photo to serialized.
*/
export const encodeLivePhoto = async (livePhoto: LivePhoto) => {
const [, imageExt] = nameAndExtension(livePhoto.imageNameTitle);
const [, videoExt] = nameAndExtension(livePhoto.videoNameTitle);