Skip to content
This repository was archived by the owner on May 7, 2026. It is now read-only.

Commit 8bffb1a

Browse files
committed
Accept IOBase instead of filename
1 parent 2e113b7 commit 8bffb1a

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

zxing/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import urllib.parse
1414
import zipfile
1515
from enum import Enum
16+
from io import IOBase
1617

1718
try:
1819
from PIL.Image import Image
@@ -59,7 +60,7 @@ def __init__(self, classpath=None, java=None):
5960
def decode(self, filenames, try_harder=False, possible_formats=None, pure_barcode=False, products_only=False):
6061
possible_formats = (possible_formats,) if isinstance(possible_formats, str) else possible_formats
6162

62-
if isinstance(filenames, (str, Image) if have_pil else str):
63+
if isinstance(filenames, (str, IOBase, Image) if have_pil else (str, IOBase)):
6364
one_file = True
6465
filenames = filenames,
6566
else:
@@ -74,6 +75,12 @@ def decode(self, filenames, try_harder=False, possible_formats=None, pure_barcod
7475
fn_or_im.save(tf, compresslevel=0)
7576
tf.flush()
7677
fn = tf.name
78+
elif isinstance(fn_or_im, IOBase):
79+
tf = NamedTemporaryFile(prefix='temp_', suffix=os.path.splitext(fn_or_im.name)[1] or '.bin')
80+
temp_files.append(tf)
81+
tf.write(fn_or_im.read())
82+
tf.flush()
83+
fn = tf.name
7784
else:
7885
fn = fn_or_im
7986
file_uris.append(pathlib.Path(fn).absolute().as_uri())

0 commit comments

Comments
 (0)