Skip to content

Commit 5156cee

Browse files
Allow bytearray and memoryview in write_stream (#31)
1 parent 22cf4d5 commit 5156cee

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

boostedblob/write.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ async def _local_write_single(
114114
@pathdispatch
115115
async def write_stream(
116116
path: Union[BasePath, BlobPath, str],
117-
stream: BoostUnderlying[bytes],
117+
stream: BoostUnderlying[Union[bytes, bytearray, memoryview]],
118118
executor: BoostExecutor,
119119
overwrite: bool = False,
120120
) -> None:
@@ -133,7 +133,7 @@ async def write_stream(
133133
@write_stream.register # type: ignore
134134
async def _azure_write_stream(
135135
path: AzurePath,
136-
stream: BoostUnderlying[bytes],
136+
stream: BoostUnderlying[Union[bytes, bytearray, memoryview]],
137137
executor: BoostExecutor,
138138
overwrite: bool = False,
139139
) -> None:
@@ -147,7 +147,7 @@ async def _azure_write_stream(
147147
md5 = hashlib.md5()
148148
max_block_index = -1
149149

150-
async def upload_chunk(index_chunk: Tuple[int, bytes]) -> None:
150+
async def upload_chunk(index_chunk: Tuple[int, Union[bytes, bytearray, memoryview]]) -> None:
151151
block_index, chunk = index_chunk
152152
# https://docs.microsoft.com/en-us/rest/api/storageservices/put-block-list#remarks
153153
assert block_index < AZURE_BLOCK_COUNT_LIMIT
@@ -172,7 +172,7 @@ async def upload_chunk(index_chunk: Tuple[int, bytes]) -> None:
172172
@write_stream.register # type: ignore
173173
async def _google_write_stream(
174174
path: GooglePath,
175-
stream: BoostUnderlying[bytes],
175+
stream: BoostUnderlying[Union[bytes, bytearray, memoryview]],
176176
executor: BoostExecutor,
177177
overwrite: bool = False,
178178
) -> None:
@@ -234,7 +234,7 @@ async def _google_write_stream(
234234
@write_stream.register # type: ignore
235235
async def _local_write_stream(
236236
path: LocalPath,
237-
stream: BoostUnderlying[bytes],
237+
stream: BoostUnderlying[Union[bytes, bytearray, memoryview]],
238238
executor: BoostExecutor,
239239
overwrite: bool = False,
240240
) -> None:
@@ -257,7 +257,7 @@ async def _local_write_stream(
257257
@pathdispatch
258258
async def write_stream_unordered(
259259
path: Union[CloudPath, str],
260-
stream: BoostUnderlying[Tuple[bytes, ByteRange]],
260+
stream: BoostUnderlying[Tuple[Union[bytes, bytearray, memoryview], ByteRange]],
261261
executor: BoostExecutor,
262262
overwrite: bool = False,
263263
) -> None:
@@ -276,7 +276,7 @@ async def write_stream_unordered(
276276
@write_stream_unordered.register # type: ignore
277277
async def _azure_write_stream_unordered(
278278
path: AzurePath,
279-
stream: BoostUnderlying[Tuple[bytes, ByteRange]],
279+
stream: BoostUnderlying[Tuple[Union[bytes, bytearray, memoryview], ByteRange]],
280280
executor: BoostExecutor,
281281
overwrite: bool = False,
282282
) -> None:
@@ -290,7 +290,9 @@ async def _azure_write_stream_unordered(
290290
upload_id = get_upload_id()
291291
block_list = []
292292

293-
async def upload_chunk(index_chunk_byte_range: Tuple[int, Tuple[bytes, ByteRange]]) -> None:
293+
async def upload_chunk(
294+
index_chunk_byte_range: Tuple[int, Tuple[Union[bytes, bytearray, memoryview], ByteRange]]
295+
) -> None:
294296
unordered_index, (chunk, byte_range) = index_chunk_byte_range
295297
# https://docs.microsoft.com/en-us/rest/api/storageservices/put-block-list#remarks
296298
assert unordered_index < AZURE_BLOCK_COUNT_LIMIT

0 commit comments

Comments
 (0)