Skip to content

Commit

Permalink
large-file-upload: update code for -B option based on feedback from PR
Browse files Browse the repository at this point in the history
The code has been updated so that if the _binaryBuffSize (which is specified
via the -B option) is larger than the notecard's binary max, the max value
is used
  • Loading branch information
youssifsaeed1 committed Jul 31, 2024
1 parent b5658a0 commit 2cc5cec
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions python-large-file-upload/notecardDataTransfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,21 @@ def _writeAndFlushBytes(self, data: io.IOBase):
while bytesSent < totalBytes:
binary_helpers.binary_store_reset(self._card)
rsp = self._sendRequest("card.binary")
max = rsp.get("max", 0)

# First set the buffer size to be equal to the max binary buffer size supported by the notecard,
# then check if the user has specified a smaller buffer size through the -B/--binary-size flag
buffSize = rsp.get("max", 0)
if self._binaryBuffSize is not None:
buffSize = self._binaryBuffSize
else:
buffSize = max
buffSize = min(self._binaryBuffSize, buffSize)

# Create a buffer of the specified size
buffer = bytearray(buffSize)
numBytes = data.readinto(buffer)

# Read the data from the file and store it in the notecard's binary store
numBytes = data.readinto(buffer)
binary_helpers.binary_store_transmit(self._card, buffer[0:numBytes], 0)


# Send the binary data to notehub
self._writeWebReqBinary(bytesSent, totalBytes)

bytesSent += numBytes
Expand Down

0 comments on commit 2cc5cec

Please sign in to comment.