Skip to content

Commit 5a10261

Browse files
committed
Merge pull request opencv#19207 from alalek:issue_19198
2 parents 0ffa78b + 0681deb commit 5a10261

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

modules/js/src/make_umd.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,16 @@
6969
import os, sys, re, json, shutil
7070
from subprocess import Popen, PIPE, STDOUT
7171

72+
PY3 = sys.version_info >= (3, 0)
73+
7274
def make_umd(opencvjs, cvjs):
73-
src = open(opencvjs, 'r+b')
74-
dst = open(cvjs, 'w+b')
75-
content = src.read()
76-
dst.seek(0)
77-
# inspired by https://github.com/umdjs/umd/blob/95563fd6b46f06bda0af143ff67292e7f6ede6b7/templates/returnExportsGlobal.js
78-
dst.write(("""
75+
with open(opencvjs, 'r+b') as src:
76+
content = src.read()
77+
if PY3: # content is bytes
78+
content = content.decode('utf-8')
79+
with open(cvjs, 'w+b') as dst:
80+
# inspired by https://github.com/umdjs/umd/blob/95563fd6b46f06bda0af143ff67292e7f6ede6b7/templates/returnExportsGlobal.js
81+
dst.write(("""
7982
(function (root, factory) {
8083
if (typeof define === 'function' && define.amd) {
8184
// AMD. Register as an anonymous module.
@@ -103,7 +106,8 @@ def make_umd(opencvjs, cvjs):
103106
Module = {};
104107
return cv(Module);
105108
}));
106-
""" % (content)).lstrip().encode())
109+
""" % (content)).lstrip().encode('utf-8'))
110+
107111

108112
if __name__ == "__main__":
109113
if len(sys.argv) > 2:

0 commit comments

Comments
 (0)