Created
July 22, 2024 22:19
-
-
Save falkorichter/1907ec157f677a0b197f1eeb2b830723 to your computer and use it in GitHub Desktop.
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
import lmdb | |
import os | |
os.environ['LMDB_FORCE_CFFI'] = '1' | |
def read_lmdb(file_path): | |
# Open the LMDB file in read-only mode | |
env = lmdb.open(file_path, readonly=True) | |
print("DB opened") | |
# Start a new transaction | |
with env.begin() as txn: | |
print("DB env.begin() called") | |
# Create a cursor to iterate through the database | |
cursor = txn.cursor() | |
# Iterate and print all key-value pairs in the database | |
for key, value in cursor: | |
ascii_string = value.decode('ascii', errors='backslashreplace') | |
print(type(value)) | |
res = ''.join(format(x, '02x') for x in value) | |
print("The string after conversion : " + str(res)) | |
print(f'Key: {key}, Value: {value} ASCII: {ascii_string}') | |
# Replace 'path/to/your/lmdbfile' with the actual path to your LMDB file | |
read_lmdb('data') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment