mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-06-27 17:42:04 +08:00
uploader.py: ensure proper resource management with io.BytesIO (#33108)
* ensure proper resource management with io.BytesIO * improve old-commit-hash: 2728c95b0d8f95faca4c1ee11a77a050f0d1c5fb
This commit is contained in:
@@ -9,7 +9,6 @@ import time
|
||||
import traceback
|
||||
import datetime
|
||||
import zstandard as zstd
|
||||
from typing import BinaryIO
|
||||
from collections.abc import Iterator
|
||||
|
||||
from cereal import log
|
||||
@@ -152,14 +151,12 @@ class Uploader:
|
||||
return FakeResponse()
|
||||
|
||||
with open(fn, "rb") as f:
|
||||
data: BinaryIO
|
||||
content = f.read()
|
||||
if key.endswith('.zst') and not fn.endswith('.zst'):
|
||||
compressed = zstd.compress(f.read(), LOG_COMPRESSION_LEVEL)
|
||||
data = io.BytesIO(compressed)
|
||||
else:
|
||||
data = f
|
||||
content = zstd.compress(content, LOG_COMPRESSION_LEVEL)
|
||||
|
||||
return requests.put(url, data=data, headers=headers, timeout=10)
|
||||
with io.BytesIO(content) as data:
|
||||
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:
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user