Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
chopping a bytearray
#2
This code looks a little strange to me because usually write() functions return the amount of data written (see for example io.BufferedWriter.write()). This data written should be at the beginning of outbuf and the code seems to chop the end of outbuf. Also the variable name 'rem' is misleading, it looks like 'remaining data' which is wrong.

Apart from that, you could perhaps write a separate function
def writeall(outfile, outbuf):
    ...

that would write all of outbuf into outfile, similarly to socket.sendall() vs socket.send(). Of course this function would read computed slices of outbuf without ever reassigning outbuf or one of its slices.
Reply


Messages In This Thread
chopping a bytearray - by Skaperen - Jul-23-2021, 01:08 AM
RE: chopping a bytearray - by Gribouillis - Jul-23-2021, 07:08 AM
RE: chopping a bytearray - by Skaperen - Jul-25-2021, 11:47 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  bytearray (and bytes) in Python2 Skaperen 3 2,932 Jun-06-2019, 05:43 AM
Last Post: heiner55
  os.path.join, bytearray, python2 vs python3 Skaperen 0 2,035 Jul-06-2018, 01:19 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020