forked from josch/img2pdf
Avoid leaking file descriptors
This change prevents img2pdf from opening *all* input files at once, which means it now works with thousands of input files.
This commit is contained in:
parent
0bdf6472f8
commit
c76f1344a5
1 changed files with 4 additions and 2 deletions
|
@ -204,7 +204,9 @@ def convert(images, dpi, x, y, title=None, author=None, creator=None, producer=N
|
||||||
pdf = pdfdoc(3, title, author, creator, producer, creationdate,
|
pdf = pdfdoc(3, title, author, creator, producer, creationdate,
|
||||||
moddate, subject, keywords)
|
moddate, subject, keywords)
|
||||||
|
|
||||||
for im in images:
|
for imfilename in images:
|
||||||
|
debug_out("Reading %s"%imfilename, verbose)
|
||||||
|
im = open(imfilename, "rb")
|
||||||
rawdata = im.read()
|
rawdata = im.read()
|
||||||
im.seek(0)
|
im.seek(0)
|
||||||
try:
|
try:
|
||||||
|
@ -295,7 +297,7 @@ def valid_date(string):
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description='Lossless conversion/embedding of images (in)to pdf')
|
description='Lossless conversion/embedding of images (in)to pdf')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'images', metavar='infile', type=argparse.FileType('rb'),
|
'images', metavar='infile', type=str,
|
||||||
nargs='+', help='input file(s)')
|
nargs='+', help='input file(s)')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-o', '--output', metavar='out', type=argparse.FileType('wb'),
|
'-o', '--output', metavar='out', type=argparse.FileType('wb'),
|
||||||
|
|
Loading…
Reference in a new issue