MCPcopy Index your code
hub / github.com/MongoEngine/mongoengine / get_file

Function get_file

tests/fields/test_file_field.py:28–35  ·  view source on GitHub ↗

Use a BytesIO instead of a file to allow to have a one-liner and avoid that the file remains opened

(path)

Source from the content-addressed store, hash-verified

26
27
28def get_file(path):
29 """Use a BytesIO instead of a file to allow
30 to have a one-liner and avoid that the file remains opened"""
31 bytes_io = BytesIO()
32 with open(path, "rb") as f:
33 bytes_io.write(f.read())
34 bytes_io.seek(0)
35 return bytes_io
36
37
38class TestFileField(MongoDBTestCase):

Calls 2

readMethod · 0.80
writeMethod · 0.45

Tested by

no test coverage detected