Firstly I'm not a real application developer, I primarily work on the web-side of things and most of the issues I'm dealing with are things I've never looked at before so I'm at a loss as to a solution for my current problem.
But I'm currently working on a small desktop application that periodically uploads a string to a website every 20-30 seconds, to reduce the time it takes and to reduce any latency issues I'm looking to gzip the string before sending it to a php script. I've gotten a few examples of the compression function on the C# side of things and plenty examples of gzip (de)compression in PHP, but after hours of looking I haven't found a way to get it to work with PHPs gzinflate(), gzdecode() or gzuncompress(). I was wondering if anyone has managed to get this type of marriage to work before?
The current c# compression function I'm using:
public static string Compress(string text)
{
byte[] buffer = Encoding.UTF8.GetBytes(text);
MemoryStream ms = new MemoryStream();
using (GZipStream zip = new GZipStream(ms, CompressionMode.Compress, true))
{
zip.Write(buffer, 0, buffer.Length);
}
ms.Position = 0;
MemoryStream outStream = new MemoryStream();
byte[] compressed = new byte[ms.Length];
ms.Read(compressed, 0, compressed.Length);
byte[] gzBuffer = new byte[compressed.Length + 4];
System.Buffer.BlockCopy(compressed, 0, gzBuffer, 4, compressed.Length);
System.Buffer.BlockCopy(BitConverter.GetBytes(buffer.Length), 0, gzBuffer, 0, 4);
return Convert.ToBase64String(gzBuffer);
}
After looking around I think the issue lies with the fact that many of the PHP functions are designed with files and because I'm using a string it has no header/footer data that it expects to see, but having never really worked with c# or gzip I have no idea how to fix the problem and any advice/help would be very much appreciated.
Yeah it's my only home/business computer.
The Surface Pen magnetic Storage is on the left side, but it doesn't charge the Pen.
I do the charging once every 6+ months by interchanging between 2 rechargeable AAAA batteries and charging the other via a USB A battery charger.
I have NO problem restricting minors having access to apps. Personally, I'd like to see the restriction extend to smartphones too, but that should be the parents anyway.
But on the restrictions ? GOOD LUCK enforcing that. Between VPN's, side loading and what not, I'm sure kids will find a way around it.
Wonder if the person that came up with the name "Cuktech" is the same person that came up for the computer name over 40 years ago WANG. When giving stock market reports, sometimes Wang was up, but sometimes Wang was down.
Wasn't it MS that got sued under violation of the Sherman antitrust act in 2001 for the way they did things on Windows with IE?
Either they don't care or didn't learn the lesson. Well, considering the outcome was 1 billion dollars, which I guess was a drop in the bucket for MS.
That's fair. Is this your only computer?
Certainly with the USB-A it can be handy when out and about, though for me the only thing would be some old thumb drives. The headphone jack is a major blow (I don't own any wireless earbuds), as is the MicroSD storage expansion which I presume is hidden behind the cover like the Pro 5 is. I don't see the surface pen storage on the 7+, is it like the one in the 12" 12th gen that charges the pen too?
Question
Asiri
Firstly I'm not a real application developer, I primarily work on the web-side of things and most of the issues I'm dealing with are things I've never looked at before so I'm at a loss as to a solution for my current problem.
But I'm currently working on a small desktop application that periodically uploads a string to a website every 20-30 seconds, to reduce the time it takes and to reduce any latency issues I'm looking to gzip the string before sending it to a php script. I've gotten a few examples of the compression function on the C# side of things and plenty examples of gzip (de)compression in PHP, but after hours of looking I haven't found a way to get it to work with PHPs gzinflate(), gzdecode() or gzuncompress(). I was wondering if anyone has managed to get this type of marriage to work before?
The current c# compression function I'm using:
public static string Compress(string text) { byte[] buffer = Encoding.UTF8.GetBytes(text); MemoryStream ms = new MemoryStream(); using (GZipStream zip = new GZipStream(ms, CompressionMode.Compress, true)) { zip.Write(buffer, 0, buffer.Length); } ms.Position = 0; MemoryStream outStream = new MemoryStream(); byte[] compressed = new byte[ms.Length]; ms.Read(compressed, 0, compressed.Length); byte[] gzBuffer = new byte[compressed.Length + 4]; System.Buffer.BlockCopy(compressed, 0, gzBuffer, 4, compressed.Length); System.Buffer.BlockCopy(BitConverter.GetBytes(buffer.Length), 0, gzBuffer, 0, 4); return Convert.ToBase64String(gzBuffer); }Example output from the function that is sent to the PHP script via post: http://www.recount.me/gzip.txt
Which I am then trying to use any of the following functions to decode:
After looking around I think the issue lies with the fact that many of the PHP functions are designed with files and because I'm using a string it has no header/footer data that it expects to see, but having never really worked with c# or gzip I have no idea how to fix the problem and any advice/help would be very much appreciated.
Thanks for reading.
Link to comment
https://www.neowin.net/forum/topic/994146-c-help-php-compatible-string-gzip/Share on other sites
2 answers to this question
Recommended Posts