Last active
June 17, 2019 19:03
-
-
Save thalesmg/9c563e4c29455b9520f6e4de012f475c to your computer and use it in GitHub Desktop.
Reading Firefox bookmark file
This file contains 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
#!/usr/bin/env python | |
# https://unix.stackexchange.com/a/434882/164273 | |
# mozlz4.py -d < $(find ~/.mozilla/firefox/8xav21dr.default/bookmarkbackups/ | sort | tail -n1) \ | |
# | jq '.children[] | select(.root == "unfiledBookmarksFolder") | .children | sort_by(.index)' | |
from sys import * | |
import os | |
try: | |
import lz4.block as lz4 | |
except ImportError: | |
import lz4 | |
stdin = os.fdopen(stdin.fileno(), 'rb') | |
stdout = os.fdopen(stdout.fileno(), 'wb') | |
if argv[1:] == ['-c']: | |
stdout.write(b'mozLz40\0' + lz4.compress(stdin.read())) | |
elif argv[1:] == ['-d']: | |
assert stdin.read(8) == b'mozLz40\0' | |
stdout.write(lz4.decompress(stdin.read())) | |
else: | |
stderr.write('Usage: %s -c|-d <infile >outfile\n' % argv[0]) | |
stderr.write('Compress or decompress Mozilla-flavor LZ4 files.\n') | |
exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment