Skip to content

Instantly share code, notes, and snippets.

@dotandimet
Created September 17, 2013 15:05
Show Gist options
  • Save dotandimet/6595595 to your computer and use it in GitHub Desktop.
Save dotandimet/6595595 to your computer and use it in GitHub Desktop.
Tie::LevelDB and binary files
use File::Slurp;
use Tie::LevelDB;
my $file_name = shift; # give the script an image file argument - preferably a PNG.
my $db = new Tie::LevelDB::DB("db/");
my $buffer;
read_file( $file_name, binmode => ':raw', buf_ref => \$buffer );
write_file( 'bin_out.png', {binmode => ':raw'}, $buffer );
$db->Put($file_name, $buffer);
my $out_buffer = $db->Get($file_name);
write_file( 'bin_out2.png', {binmode => ':raw'}, $out_buffer );
# bin_out2.png is unfortunately much shorter than bin_out.png :-(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment