Spaces:
Paused
Paused
Download src/utils/filesystem/writeBase64ToFile.mts from jbilcke-hf/VideoChain-API: direct link, hf CLI and curl.
- Browser
- Download file 527 Bytes
-
https://huggingface.co/spaces/jbilcke-hf/VideoChain-API/resolve/cd4ee95e1e76fb32012ff8216dcaad5839176a8a/src/utils/filesystem/writeBase64ToFile.mts
- Command line
-
hf download hf://spaces/jbilcke-hf/VideoChain-API@cd4ee95e1e76fb32012ff8216dcaad5839176a8a/src/utils/filesystem/writeBase64ToFile.mts
-
curl -L -o writeBase64ToFile.mts https://huggingface.co/spaces/jbilcke-hf/VideoChain-API/resolve/cd4ee95e1e76fb32012ff8216dcaad5839176a8a/src/utils/filesystem/writeBase64ToFile.mts
527 Bytes
| import { promises as fs } from "node:fs" | |
| export async function writeBase64ToFile(content: string, filePath: string): Promise<void> { | |
| // Remove "data:image/png;base64," from the start of the data url | |
| const base64Data = content.split(",")[1] | |
| // Convert base64 to binary | |
| const data = Buffer.from(base64Data, "base64") | |
| // Write binary data to file | |
| try { | |
| await fs.writeFile(filePath, data) | |
| // console.log("File written successfully") | |
| } catch (error) { | |
| console.error("An error occurred:", error) | |
| } | |
| } |