Skip to content

Instantly share code, notes, and snippets.

@gildas-lormeau
Last active September 3, 2023 12:43
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gildas-lormeau/f05b65a8654587ea89857c0213d809a9 to your computer and use it in GitHub Desktop.
Save gildas-lormeau/f05b65a8654587ea89857c0213d809a9 to your computer and use it in GitHub Desktop.
CLI to transform a SingleFileZ page into a SingleFile page
import { extract } from "https://raw.githubusercontent.com/gildas-lormeau/single-filez-core/main/processors/compression/compression-extract.js";
import * as zip from "https://raw.githubusercontent.com/gildas-lormeau/zip.js/master/index.js";
globalThis.zip = zip;
const { docContent } = await extract(new Blob([await Deno.readFile(Deno.args[0])]), { noBlobURL: true });
if (Deno.args[1]) {
await Deno.writeTextFile(Deno.args[1], docContent);
} else {
console.log(docContent);
}
#!/bin/sh
if [ $# -eq 0 ]; then
echo
echo " Usage: $0 <INPUT FILE> [OUTPUT FILE]"
echo
echo " Transforms a page saved with SingleFileZ into a SingleFile page."
echo
echo " Arguments:"
echo
echo " INPUT FILE: path to a file containing a page saved with SingleFileZ"
echo " OUTPUT FILE: path of the output file"
echo
exit 1
else
deno run --allow-read --allow-write ./sfz2sf.js "$1" "$2"
fi
@gildas-lormeau
Copy link
Author

@nitincodery
Copy link

nitincodery commented Jan 11, 2023

This is equivalent batch script for windows, if anyone needs:

Edit: Fixed input filenames with spaces.

sfz2sf.bat

@echo off

if "%~1" == "" (
    echo Usage: %0 ^<INPUT FILE^> [OUTPUT FILE]
    echo Transforms a page saved with SingleFileZ into a SingleFile page.
    echo Arguments:
    echo INPUT FILE: path to a file containing a page saved with SingleFileZ
    echo OUTPUT FILE: path of the output file
    exit /b 1
) else (
    deno run --allow-read --allow-write .\sfz2sf.js "%~1" "%~2"
)

@nitincodery
Copy link

It expects SFZ with .zip.html extension as input and save them as SF with .html extension with same filename, removing the option to give output filename. Also updating %1 with %~1, as it was giving error with filenames having space, so latter fixes that.

sfz2sf.bat

@echo off

if "%~1" == "" (
    echo Usage: %0 ^<INPUT FILE^>
    echo Transforms a page saved with SingleFileZ into a SingleFile page.
    echo Arguments:
    echo INPUT FILE: path to a file containing a page saved with SingleFileZ
    exit /b 1
) else (
    deno run --allow-read --allow-write .\sfz2sf.js "%~1"
)

sfz2sf.js

import { extract } from "https://raw.githubusercontent.com/gildas-lormeau/single-filez-core/main/processors/compression/compression-extract.js";
import * as zip from "https://raw.githubusercontent.com/gildas-lormeau/zip.js/master/index.js";

globalThis.zip = zip;
const { docContent } = await extract(new Blob([await Deno.readFile(Deno.args[0])]), { noBlobURL: true });
await Deno.writeTextFile(Deno.args[0].split(".")[0].concat(".html"), docContent);

@gildas-lormeau
Copy link
Author

Thank you very much @nitincodery!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment