Skip to content

Commit 771d326

Browse files
committed
Merge remote-tracking branch 'origin/master' into edge
2 parents f525f9d + d538083 commit 771d326

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

mig/shared/fileio.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ def _write_chunk(path, chunk, offset, logger=None, mode='r+b',
7676
The optional make_parent and create_file are used to decide if the parent
7777
directory and the file should be created if it doesn't already exist.
7878
"""
79-
if not logger:
80-
logger = null_logger("dummy")
8179
# logger.debug("writing chunk to %r at offset %d" % (path, offset))
8280

8381
if offset < 0:
@@ -130,6 +128,13 @@ def write_chunk(path, chunk, offset, logger, mode='r+b'):
130128
"""Wrapper to handle writing of chunks with offset to path.
131129
Creates file first if it doesn't already exist.
132130
"""
131+
if not logger:
132+
logger = null_logger("dummy")
133+
134+
# NOTE: detect byte writes and handle explicitly in a portable way
135+
if isinstance(chunk, bytes) and 'b' not in mode:
136+
mode = "%sb" % mode # appended to avoid mode ordering error on PY2
137+
133138
return _write_chunk(path, chunk, offset, logger, mode)
134139

135140

0 commit comments

Comments
 (0)