1

I'm trying to send multiple GZipped files in the same request, with a string delimiter, which are then supposed to be read by GZip Stream individually.

The problem I'm having is that I can either split the string (using UTF-8 encoding) or decompress the GZip (when using Unicode), but I need to be able to do both. It has to be something simple that I'm overlooking.

In short:

Encoding.UTF8.GetBytes(Encoding.UTF8.GetString(byteArray)) returns a different byte array from the original. The same happens with ASCII.

Encoding.Unicode.GetBytes(Encoding.Unicode.GetString(byteArray)) returns the same byte array as the original, but for some reason I'm unable to split the received data using my delimiter (for example: Encoding.Unicode.GetString(byteArray).Split(new string[] { delimiter }, StringSplitOptions.None) doesn't find the delimiter and returns a string array with one element, the full string). Each file is 15-20KB, so I can't paste them here.

What am I missing?

I can do it with BitConverter and looking for the delimiter as a HEX value, but there has to be a better way.

I'm not listening for requests, but I make an API request from the app (the server is vanilla PHP7), and get the files in the response. Using Unity's WWW class.

Shomz
  • 37,421
  • 4
  • 57
  • 85
  • How do you get those `multiple GZIP files in one request`? there may be other solutions. I hope it is not an [XY problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem) – L.B Aug 30 '17 at 21:18
  • @L.B Modifying a system which was sending a single GZIP file so that it can send multiple now. Using a simple delimiter to save bandwidth. The files are not the same size. – Shomz Aug 30 '17 at 21:21
  • Have you tried to use [`multipart content`](https://stackoverflow.com/questions/16958448/what-is-http-multipart-request). Yes question appears to be an xy problem. – L.B Aug 30 '17 at 21:22
  • I was considering it, but wasn't sure how would that help me read the parts individually in c#. Is that what I should do? – Shomz Aug 30 '17 at 21:25
  • Surely... this is the correct way of multi file content. Just try it, if you get poblems of using that approach, post that specific question – L.B Aug 30 '17 at 21:27
  • Thank you, will do. Before I delete this, can you tell me from the top of your head what's the best way to read such data? – Shomz Aug 30 '17 at 21:28
  • Which framework do you use. I use WCF and have answer for it. But in general there are many libraries to parse a *multipart content* (BTW: Doing it manually isn't also that hard) – L.B Aug 30 '17 at 21:32
  • It's a Unity3D app. I'd probably do it manually. – Shomz Aug 30 '17 at 21:34
  • Framework you *listen* for incoming requests? WCF, WebApi, HttpListener etc..? Anyway it is possible.. – L.B Aug 30 '17 at 21:35
  • I'm not listening for requests, but I make an API request from the app (the server is vanilla PHP7), and get the files in the response. Using Unity's [WWW](https://docs.unity3d.com/ScriptReference/WWW.html) class. – Shomz Aug 30 '17 at 21:42
  • I am not familiar with those. But I am sure someone has did it before – L.B Aug 30 '17 at 21:47
  • 1
    Alright, thank you again for your help. – Shomz Aug 30 '17 at 21:48

0 Answers0