mirror of https://github.com/commaai/openpilot.git
uploader.py: ensure proper resource management with io.BytesIO (#33108)
* ensure proper resource management with io.BytesIO
* improve
old-commit-hash: 2728c95b0d
This commit is contained in:
parent
3e39d610bc
commit
3c1af12490
|
@ -9,7 +9,6 @@ import time
|
||||||
import traceback
|
import traceback
|
||||||
import datetime
|
import datetime
|
||||||
import zstandard as zstd
|
import zstandard as zstd
|
||||||
from typing import BinaryIO
|
|
||||||
from collections.abc import Iterator
|
from collections.abc import Iterator
|
||||||
|
|
||||||
from cereal import log
|
from cereal import log
|
||||||
|
@ -152,13 +151,11 @@ class Uploader:
|
||||||
return FakeResponse()
|
return FakeResponse()
|
||||||
|
|
||||||
with open(fn, "rb") as f:
|
with open(fn, "rb") as f:
|
||||||
data: BinaryIO
|
content = f.read()
|
||||||
if key.endswith('.zst') and not fn.endswith('.zst'):
|
if key.endswith('.zst') and not fn.endswith('.zst'):
|
||||||
compressed = zstd.compress(f.read(), LOG_COMPRESSION_LEVEL)
|
content = zstd.compress(content, LOG_COMPRESSION_LEVEL)
|
||||||
data = io.BytesIO(compressed)
|
|
||||||
else:
|
|
||||||
data = f
|
|
||||||
|
|
||||||
|
with io.BytesIO(content) as data:
|
||||||
return requests.put(url, data=data, headers=headers, timeout=10)
|
return requests.put(url, data=data, headers=headers, timeout=10)
|
||||||
|
|
||||||
def upload(self, name: str, key: str, fn: str, network_type: int, metered: bool) -> bool:
|
def upload(self, name: str, key: str, fn: str, network_type: int, metered: bool) -> bool:
|
||||||
|
|
Loading…
Reference in New Issue