#๐Ÿ”’ How to detect individual files sent over socket?

15 messages ยท Page 1 of 1 (latest)

glass tapirBOT
#

Hey @plush marsh!

It looks like you pasted Python code without syntax highlighting.

Please use syntax highlighting to improve the legibility of your code and make it easier for us to help you.

To do this, use the following method:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
You can **edit your original message** to correct your code block.
#

@plush marsh

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

plush marsh
#

Not sure what happend to my description but it got automatically deleted when I posted

#

using this:

for path in pathlib.Path(Paths.my_datadir).iterdir():
        ...
        #print(path)
        if 'zip' in str(path):
            ...
            try:
                f = open(path, 'rb')
                Net.Send({'subject': 'data', 'header': 'upload started'})
                while True:
                    ...
                    read = f.read(Net.buffer)
                    print(f'buffer data: {read}')

                    if not read:
                        break
                    sleep(1)
                Net.Send({'subject': 'data', 'footer': 'upload finished'})
#

i sent: buffer data: b'PK\x03\x04\x14\x00\x00\x00\x08\x00\xdd\xb99XZH\x8e\xd2\xbd\x10\x00\x00\xc8\x10\x00\x00\x05\x00\x00\x00w.p12e\x96uT\x13\x8e\xbb\xc6\xd9\x18#\x1c\x8d\xa4t\xf7F\xa7\x12\x02\x82\xe4\x08\xa5\xeb+9\xba\x1b\x06\x0cA\x1a\xa4d\x84\xd4\x84\x11\xd2HH\xc8\x08i\x14\x04\x04a\xa8H\x83\xa4\xe4\xcf\xdf9\xf7\xde\xdf\xbd\xe7\xfe\xf1\x9e\xf7\xbc\x9f\xe7<\xef\xbf\xcf\x03ER}\x00\x02\x08\xa1H\xaa$0\xa9\x10\xea\x11\xea\x8c\x1c@\x0c(AR\x85\x81\x90TA\x7f\xb1\x1f\x14I2\xff\x1f\t\\x82$\x19\xfe\x8b\xfe\x9a\x08\xfe\xae\xee\xffe\x82\xde\x03\x93\xfd\xd7\x01\xf9\xfb\x91\x02D\x92Gp\x8f?...

#

buffer data: b'\xb9\x7f\xcefEh\x16J\t"\xa5\x7f\xab\xebj\xceg\x0f\x9d9S\xcbsIE\xed\xee\x99\xf2vM%\xfd3\xc2\xf5\x9a\x01\x19\xbe\x149)\x9c\x88\xb1(\xb5\xcaH\n\x90\xbe&y\xb7\xfa\xd9>\xa9\x84\xaf@\x88{\xd2\x93)<l\xd1\xa6\xe7\xb2\x89FO\xb1C \xbe\x92\xea\x1f^hT\xd3"\xb0I\xdd\x92\xfd\xd6\x1a\xa7F\xbf\xcb\xefX~yK\x1fS\x84\x05\x82\x8f}Y0\xe4\xe8\x0c\xc9\x8f4;\xa4K\xcd\x94\xefh\xed\xe8rP\xea\xffIWR:\x18\x88\rH\x10\x04\xe5\xfe\x0f\xba\x0b\xa3\x07\xd15r\xa4\xea\xe0\xf2\x08,\x9f\x17\xe4\xbb\n\x0e\x12\x12\x89\x1a\n\xd7@aPN()\x98H\x98\x82\x10\xc8LD\x00\xa2\x0b\xda\x17\xd0\x84\x0f\xf9\x1b]\xe5T\x06\xdd\xdef8\xc0\x8e\x1fA$\xc9p\t\xda\xb0\x0c`\xea\xbf\x83\xf7_PK\x01\x02\x14\x00\x14\x00\x00\x00\x08\x00\xdd\xb99XZH\x8e\xd2\xbd\x10\x00\x00\xc8\x10\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb6\x81\x00\x00\x00\x00w.p12PK\x05\x06\x00\x00\x00\x00\x01\x00\x01\x003\x00\x00\x00\xe0\x10\x00\x00\x00\x00'

#

beccause it only 1024 bytes per chunk, i notice that beginning files have "PK" and ending have 'x00'

#

using these would it help differentiate spearate files?

#

separate

willow locust
#

No.

#

The proper way to do this is to prepend a header that describes the data (including length)

#

And then when you read you check if you have a full payload and then do work with it

carmine crescent
glass tapirBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.