Created
May 29, 2023 18:49
-
-
Save Guestman360/e007f57e7097ff413ab2dcc63f90c8fb to your computer and use it in GitHub Desktop.
Code snippet for zipping and converting to base64
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import fs from 'fs'; | |
| import * as path from 'path'; | |
| import shell from 'shelljs'; | |
| export const createZipWithBase64 = (user_id: string, code: string): string => { | |
| fs.writeFileSync(`${path.join(__dirname, '/cpp/additional_files/main.cpp')}`, code); | |
| // packaging in a zip archive and encoding in base64 | |
| shell.exec('base64 -v'); | |
| shell.exec('base64 --help'); | |
| shell.exec( | |
| `cd ${path.join(__dirname, '/cpp/additional_files')} || exit; zip -r - . | base64 > ${path.resolve( | |
| __dirname, | |
| `../../zip_b64/${user_id}.txt`, | |
| )}`, | |
| ); | |
| // reading result base64 from a file | |
| const zip_b64 = fs.readFileSync(`${path.resolve(__dirname, `../../zip_b64/${user_id}.txt`)}`).toString(); | |
| return zip_b64; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment