Skip to content

Instantly share code, notes, and snippets.

@hryk
Created October 26, 2010 10:05
Show Gist options
  • Select an option

  • Save hryk/646636 to your computer and use it in GitHub Desktop.

Select an option

Save hryk/646636 to your computer and use it in GitHub Desktop.
generate data url.
#!/usr/bin/env perl
use strict;
use warnings;
use File::MimeInfo::Magic;
@File::MimeInfo::DIRS = qw(/usr/local/share/mime/);
File::MimeInfo->rehash();
use URI;
my $input_file = $ARGV[0];
unless ($input_file) {
while (<DATA>){
print STDERR $_;
}
exit 1;
}
my $mime_type = mimetype($input_file);
my $url = URI->new("data:");
$url->media_type($mime_type);
$url->data(scalar(`cat $input_file`));
print "\n$url\n";
__DATA__
dataurl
command line tool for generate data-url scheme.
Usage:
dataurl [FILE]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment