Skip to content

Commit 9dff99d

Browse files
authored
Use write_file/read_file in file_packager.py. NFC (#19290)
1 parent c513aed commit 9dff99d

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

tools/file_packager.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,7 @@ def main():
410410
options.from_emcc = True
411411
leading = ''
412412
elif arg.startswith('--plugin'):
413-
with open(arg.split('=', 1)[1]) as f:
414-
plugin = f.read()
413+
plugin = utils.read_file(arg.split('=', 1)[1])
415414
eval(plugin) # should append itself to plugins
416415
leading = ''
417416
elif leading == 'preload' or leading == 'embed':
@@ -556,17 +555,13 @@ def was_seen(name):
556555
# differs from the current generated one, otherwise leave the file
557556
# untouched preserving its old timestamp
558557
if os.path.isfile(options.jsoutput):
559-
with open(options.jsoutput) as f:
560-
old = f.read()
558+
old = utils.read_file(options.jsoutput)
561559
if old != ret:
562-
with open(options.jsoutput, 'w') as f:
563-
f.write(ret)
560+
utils.write_file(options.jsoutput, ret)
564561
else:
565-
with open(options.jsoutput, 'w') as f:
566-
f.write(ret)
562+
utils.write_file(options.jsoutput, ret)
567563
if options.separate_metadata:
568-
with open(options.jsoutput + '.metadata', 'w') as f:
569-
json.dump(metadata, f, separators=(',', ':'))
564+
utils.write_file(options.jsoutput + '.metadata', json.dumps(metadata, separators=(',', ':')))
570565

571566
return 0
572567

@@ -617,8 +612,7 @@ def generate_js(data_target, data_files, metadata):
617612
with open(data_target, 'wb') as data:
618613
for file_ in data_files:
619614
file_.data_start = start
620-
with open(file_.srcpath, 'rb') as f:
621-
curr = f.read()
615+
curr = utils.read_binary(file_.srcpath)
622616
file_.data_end = start + len(curr)
623617
if AV_WORKAROUND:
624618
curr += '\x00'

0 commit comments

Comments
 (0)