public override void SendAsync(byte[] data, Func <byte[], bool> callback) { var request = (HttpWebRequest)WebRequest.Create(_url); request.Method = "POST"; request.ContentType = "application/octetstream"; request.ContentLength = data.Length; request.Timeout = 1000 * 10; using (Stream stream = request.GetRequestStream()) { stream.Write(data, 0, data.Length); stream.Close(); } byte[] result = new byte[0]; WebResponse resp = request.GetResponse(); using (Stream stream = resp.GetResponseStream()) { if (stream != null) { var reader = new BinaryReader(stream); result = ReadStream(reader); } } if ((result.Length > 3 && result[0] == 0x1f && result[0 + 1] == 0x8b && result[0 + 2] == 0x08 && result[0 + 3] == 0x00)) { result = GzipUtils.DeCompress(result, 0, result.Length); } callback(result); }
public void CompressionDecompressionTest() { var compressedResult = GzipUtils.Compress(InputString); var decompressedResult = GzipUtils.Decompress(compressedResult); Assert.AreEqual(InputString, decompressedResult); }
/// <summary> /// Loads the dictionary. If the dictionary is not found by its key and postfix, the empty dictionary is created. /// </summary> /// <param name="key">The key.</param> /// <param name="postfix">The postfix.</param> /// <param name="dict">The dictionary.</param> /// <returns></returns> private bool LoadDictionary(string key, string postfix, ref IDictionary <string, string> dict) { key = key.Replace("-", "_"); bool isFound = false; string resourceName = $"language.{key}.{postfix}.json.gz"; string targetManifestResourceName = this .GetType().Assembly .GetManifestResourceNames() .Where(i => i.EndsWith(resourceName)).FirstOrDefault(); if (targetManifestResourceName != null) { using (Stream resourceStream = this.GetType().Assembly.GetManifestResourceStream(targetManifestResourceName)) { using (StreamReader streamReader = new StreamReader(resourceStream)) { var compressedResourceValue = streamReader.ReadToEnd(); var decompressedResourceValue = GzipUtils.Decompress(compressedResourceValue); dict = JsonConvert.DeserializeObject <ResourceLocale>(decompressedResourceValue).Values; isFound = true; } } } if (!isFound && dict == null) { dict = new Dictionary <string, string>(); } return(isFound); }
/// <summary> /// Prepares CDX parsing. /// </summary> /// <param name="cdxStream">The stream containing the CDX file.</param> /// <param name="warcIO">The WARC file matching the CDX file.</param> /// <param name="warcName">Tells the parser which WARC to look for inside the CDX. Since CDX may contain entries to multiple WARCs, /// you have to specify the WARC name here.</param> public CDXParser(Stream cdxStream, Stream warcIO, string warcName) { this.warcIO = warcIO; this.warcName = warcName; if (GzipUtils.isGzip(cdxStream)) { cdxStream = new GZipStream(cdxStream, CompressionMode.Decompress); } cdxIO = new StreamReader(cdxStream); }
public void IsCompressedTest() { string longString = LongString; int longStringLength = longString.Length; var result = GzipUtils.Compress(longString); int resultLength = result.Length; Assert.IsTrue(resultLength < longStringLength); }