public static string Decompress(string fname, bool forceOverwrite) { var outFname = Path.GetFileNameWithoutExtension(fname); if (File.Exists(outFname)) { if (forceOverwrite) { File.Delete(outFname); } else { return(null); } } using (var fs = File.OpenRead(fname)) { using (var decompressor = new Ionic.Zlib.GZipStream(fs, Ionic.Zlib.CompressionMode.Decompress)) { using (var output = File.Create(outFname)) { Pump(decompressor, output); } } } return(outFname); }
static string Compress(string fname, bool forceOverwrite) { var outFname = fname + ".gz"; if (File.Exists(outFname)) { if (forceOverwrite) File.Delete(outFname); else return null; } using (var fs = File.OpenRead(fname)) { using (var output = File.Create(outFname)) { using (var compressor = new Ionic.Zlib.GZipStream(output, Ionic.Zlib.CompressionMode.Compress)) { compressor.FileName = fname; var fi = new FileInfo(fname); compressor.LastModified = fi.LastWriteTime; Pump(fs, compressor); } } } return outFname; }
/// <summary> /// Decompresses the file at the given path. Returns the path of the /// decompressed file. /// </summary> /// <param name="path">The path to decompress.</param> /// <returns>The path of the decompressed file.</returns> public string Decompress(string path) { string outputPath = Regex.Replace(path, @"\.gz$", String.Empty, RegexOptions.IgnoreCase); if (File.Exists(outputPath)) { File.Delete(outputPath); } using (FileStream fs = File.OpenRead(path)) { using (FileStream output = File.Create(outputPath)) { using (GZipStream gzip = new GZipStream(fs, CompressionMode.Decompress)) { byte[] buffer = new byte[4096]; int count = 0; while (0 < (count = gzip.Read(buffer, 0, buffer.Length))) { output.Write(buffer, 0, count); } } } } return outputPath; }
static string Compress(string fname, bool forceOverwrite) { var outFname = fname + ".gz"; if (File.Exists(outFname)) { if (forceOverwrite) { File.Delete(outFname); } else { return(null); } } using (var fs = File.OpenRead(fname)) { using (var output = File.Create(outFname)) { using (var compressor = new Ionic.Zlib.GZipStream(output, Ionic.Zlib.CompressionMode.Compress)) { Pump(fs, compressor); } } } return(outFname); }
/// <summary> /// Compresses the file at the given path. Returns the path to the /// compressed file. /// </summary> /// <param name="path">The path to compress.</param> /// <returns>The path of the compressed file.</returns> public string Compress(string path) { string outputPath = String.Concat(path, ".gz"); if (File.Exists(outputPath)) { File.Delete(outputPath); } using (FileStream fs = File.OpenRead(path)) { using (FileStream output = File.Create(outputPath)) { using (GZipStream gzip = new GZipStream(output, CompressionMode.Compress, CompressionLevel.BestCompression)) { byte[] buffer = new byte[4096]; int count = 0; while (0 < (count = fs.Read(buffer, 0, buffer.Length))) { gzip.Write(buffer, 0, count); } } } } return outputPath; }
/// <summary> /// 지정된 데이타를 압축한다. /// </summary> /// <param name="input">압축할 Data</param> /// <returns>압축된 Data</returns> public override byte[] Compress(byte[] input) { if(IsDebugEnabled) log.Debug(CompressorTool.SR.CompressStartMsg); // check input data if(input.IsZeroLength()) { if(IsDebugEnabled) log.Debug(CompressorTool.SR.InvalidInputDataMsg); return CompressorTool.EmptyBytes; } byte[] output; using(var outStream = new MemoryStream(input.Length)) { using(var gzip = new GZipStream(outStream, CompressionMode.Compress)) { gzip.Write(input, 0, input.Length); } output = outStream.ToArray(); } if(IsDebugEnabled) log.Debug(CompressorTool.SR.CompressResultMsg, input.Length, output.Length, output.Length / (double)input.Length); return output; }
public override void Execute(object parameter) { var saveFile = new SaveFileDialog { /*TODO, In Silverlight 5: DefaultFileName = string.Format("Dump of {0}, {1}", ApplicationModel.Database.Value.Name, DateTimeOffset.Now.ToString()), */ DefaultExt = ".raven.dump", Filter = "Raven Dumps|*.raven.dump", }; if (saveFile.ShowDialog() != true) return; stream = saveFile.OpenFile(); gZipStream = new GZipStream(stream, CompressionMode.Compress); streamWriter = new StreamWriter(gZipStream); jsonWriter = new JsonTextWriter(streamWriter) { Formatting = Formatting.Indented }; output(String.Format("Exporting to {0}", saveFile.SafeFileName)); output("Begin reading indexes"); jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("Indexes"); jsonWriter.WriteStartArray(); ReadIndexes(0).Catch(exception => Infrastructure.Execute.OnTheUI(() => Finish(exception))); }
public override void Execute(object parameter) { var saveFile = new SaveFileDialog { DefaultExt = ".raven.dump", Filter = "Raven Dumps|*.raven.dump" }; var dialogResult = saveFile.ShowDialog() ?? false; if (!dialogResult) return; stream = saveFile.OpenFile(); gZipStream = new GZipStream(stream, CompressionMode.Compress); streamWriter = new StreamWriter(gZipStream); jsonWriter = new JsonTextWriter(streamWriter) { Formatting = Formatting.Indented }; output(string.Format("Exporting to {0}", saveFile.SafeFileName)); output("Begin reading indexes"); jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("Indexes"); jsonWriter.WriteStartArray(); ReadIndexes(0).Catch(exception => Infrastructure.Execute.OnTheUI(() => Finish(exception))); }
public void uncompress(Stream inStream, Stream outStream) { GZipStream compressionStream = new GZipStream(inStream, CompressionMode.Decompress, true); compressionStream.CopyTo(outStream); }
public byte[] Decompress(Stream inputStream) { using (var gzipStream = new GZipStream(inputStream, CompressionMode.Decompress)) using (var outputStream = new MemoryStream()) { gzipStream.WriteTo(outputStream); return outputStream.ToArray(); } }
public override void Execute(object parameter) { TaskCheckBox attachmentUI = taskModel.TaskInputs.FirstOrDefault(x => x.Name == "Include Attachments") as TaskCheckBox; includeAttachments = attachmentUI != null && attachmentUI.Value; var saveFile = new SaveFileDialog { DefaultExt = ".ravendump", Filter = "Raven Dumps|*.ravendump;*.raven.dump", }; var name = ApplicationModel.Database.Value.Name; var normalizedName = new string(name.Select(ch => Path.GetInvalidPathChars().Contains(ch) ? '_' : ch).ToArray()); var defaultFileName = string.Format("Dump of {0}, {1}", normalizedName, DateTimeOffset.Now.ToString("dd MMM yyyy HH-mm", CultureInfo.InvariantCulture)); try { saveFile.DefaultFileName = defaultFileName; } catch { } if (saveFile.ShowDialog() != true) return; taskModel.CanExecute.Value = false; stream = saveFile.OpenFile(); gZipStream = new GZipStream(stream, CompressionMode.Compress); streamWriter = new StreamWriter(gZipStream); jsonWriter = new JsonTextWriter(streamWriter) { Formatting = Formatting.Indented }; taskModel.TaskStatus = TaskStatus.Started; output(String.Format("Exporting to {0}", saveFile.SafeFileName)); jsonWriter.WriteStartObject(); Action finalized = () => { jsonWriter.WriteEndObject(); Infrastructure.Execute.OnTheUI(() => Finish(null)); }; Action readAttachments = () => ReadAttachments(Guid.Empty, 0, callback: finalized); Action readDocuments = () => ReadDocuments(Guid.Empty, 0, callback: includeAttachments ? readAttachments : finalized); try { ReadIndexes(0, callback: readDocuments); } catch (Exception ex) { taskModel.ReportError(ex); Infrastructure.Execute.OnTheUI(() => Finish(ex)); } }
static public byte[] compress(byte[] bytes) { var output = new MemoryStream(); var gzipStream = new GZipStream(output, CompressionMode.Compress, true); gzipStream.Write(bytes, 0, bytes.Length); gzipStream.Close(); return output.ToArray(); }
public void compress(Stream inStream, Stream outStream) { GZipStream compressionStream = new GZipStream(outStream, CompressionMode.Compress, true); inStream.CopyTo(compressionStream); compressionStream.Close(); }
public static void Compress(byte[] data, string path) { using (GZipStream gzip = new GZipStream( new FileStream(path, FileMode.Create, FileAccess.Write), CompressionMode.Compress, CompressionLevel.BestCompression, false)) { gzip.Write(data, 0, data.Length); gzip.Flush(); } }
public static byte[] CompressGzip(byte[] bytes) { using (var ms = new MemoryStream()) { using (var zip = new GZipStream(ms, CompressionMode.Compress, true)) { zip.Write(bytes, 0, bytes.Length); } return ms.ToArray(); } }
public static void ZipStreamDecompress(Stream source, Stream dest) { using (var stream = new Ionic.Zlib.GZipStream(source, Ionic.Zlib.CompressionMode.Decompress, true)) { var buf = new byte[ZIP_BUFFER_SIZE]; int len; while ((len = stream.Read(buf, 0, buf.Length)) > 0) { dest.Write(buf, 0, len); } } }
public static byte[] Compress(byte[] data) { MemoryStream output = new MemoryStream(); using (GZipStream gzip = new GZipStream( output, CompressionMode.Compress, CompressionLevel.BestCompression, true)) { gzip.Write(data, 0, data.Length); gzip.Flush(); } return output.ToArray(); }
public static int Main(string[] args) { var inputFile = args[0]; var targetFolder = args[1]; if (!Directory.Exists(targetFolder)) Directory.CreateDirectory(targetFolder); var language = _GetLanguage(args); var type = _GetGramType(args); var fictionOnly = args.Any(x => x.ToLower() == "fiction"); var versionDate = args.Single(x => x.All(Char.IsNumber)); var includeDependencies = args.Any(x => x.ToLower() == "include0"); var rawHrefs = File.ReadAllLines(inputFile).Select(_GetHref).Where(x => x != null).Select(x => x.ToLower()); var filtered = rawHrefs .Where(x => x.Contains(_GetNGramTypeForFilter(type).ToLower())) .Where(x => _FilterByLanguage(x, language)) .Where(x => x.Contains(versionDate)).ToArray(); var connectionString = @"Data Source=.\mssql12;Initial Catalog=NGram;Integrated Security=True"; var oneGramLoader = new OneGramLoader(); foreach (var rawHref in filtered) { Console.WriteLine("Downloading href {0}", rawHref); var req = WebRequest.CreateHttp(rawHref); var res = req.GetResponse(); using (var resStream = res.GetResponseStream()) { using (var zipStream = new GZipStream(resStream, CompressionMode.Decompress)) { using (var sr = new StreamReader(zipStream)) { oneGramLoader.ProcessOneGram(sr, connectionString); } zipStream.Close(); } resStream.Close(); } } Console.WriteLine("Finished - any key"); Console.ReadLine(); return 0; }
public const int CacheControlOneWeekExpiration = 7 * 24 * 60 * 60; // 1 week #endregion Fields #region Methods /// <summary> /// Finds all js and css files in a container and creates a gzip compressed /// copy of the file with ".gzip" appended to the existing blob name /// </summary> public static void EnsureGzipFiles( CloudBlobContainer container, int cacheControlMaxAgeSeconds) { string cacheControlHeader = "public, max-age=" + cacheControlMaxAgeSeconds.ToString(); var blobInfos = container.ListBlobs( new BlobRequestOptions() { UseFlatBlobListing = true }); Parallel.ForEach(blobInfos, (blobInfo) => { string blobUrl = blobInfo.Uri.ToString(); CloudBlob blob = container.GetBlobReference(blobUrl); // only create gzip copies for css and js files string extension = Path.GetExtension(blobInfo.Uri.LocalPath); if (extension != ".css" && extension != ".js") return; // see if the gzip version already exists string gzipUrl = blobUrl + ".gzip"; CloudBlob gzipBlob = container.GetBlobReference(gzipUrl); if (gzipBlob.Exists()) return; // create a gzip version of the file using (MemoryStream memoryStream = new MemoryStream()) { // push the original blob into the gzip stream using (GZipStream gzipStream = new GZipStream( memoryStream, CompressionMode.Compress, CompressionLevel.BestCompression)) using (BlobStream blobStream = blob.OpenRead()) { blobStream.CopyTo(gzipStream); } // the gzipStream MUST be closed before its safe to read from the memory stream byte[] compressedBytes = memoryStream.ToArray(); // upload the compressed bytes to the new blob gzipBlob.UploadByteArray(compressedBytes); // set the blob headers gzipBlob.Properties.CacheControl = cacheControlHeader; gzipBlob.Properties.ContentType = GetContentType(extension); gzipBlob.Properties.ContentEncoding = "gzip"; gzipBlob.SetProperties(); } }); }
public string TwitterLinkBuilder(string q) { string ret = string.Empty; JArray output = new JArray(); SortedDictionary<string, string> requestParameters = new SortedDictionary<string, string>(); try { var oauth_url = " https://api.twitter.com/1.1/search/tweets.json?q=" + q.Trim() + "&result_type=recent"; var headerFormat = "Bearer {0}"; var authHeader = string.Format(headerFormat, "AAAAAAAAAAAAAAAAAAAAAOZyVwAAAAAAgI0VcykgJ600le2YdR4uhKgjaMs%3D0MYOt4LpwCTAIi46HYWa85ZcJ81qi0D9sh8avr1Zwf7BDzgdHT"); var postBody = requestParameters.ToWebString(); ServicePointManager.Expect100Continue = false; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(oauth_url + "?" + requestParameters.ToWebString()); request.Headers.Add("Authorization", authHeader); request.Method = "GET"; request.Headers.Add("Accept-Encoding", "gzip"); HttpWebResponse response = request.GetResponse() as HttpWebResponse; Stream responseStream = new GZipStream(response.GetResponseStream(), CompressionMode.Decompress); using (var reader = new StreamReader(responseStream)) { var objText = reader.ReadToEnd(); output = JArray.Parse(JObject.Parse(objText)["statuses"].ToString()); } List<string> _lst = new List<string>(); foreach (var item in output) { try { string _urls = item["entities"]["urls"][0]["expanded_url"].ToString(); if (!string.IsNullOrEmpty(_urls)) _lst.Add(_urls); } catch { } } ret = new JavaScriptSerializer().Serialize(_lst); } catch (Exception ex) { logger.Error(ex.Message); ret = ""; } return ret; }
public static void Decompress(byte[] data, string path) { byte[] buffer = new byte[BufferSize]; int read; using (FileStream output = new FileStream(path, FileMode.Create, FileAccess.Write)) using (GZipStream gzip = new GZipStream(new MemoryStream(data), CompressionMode.Decompress, CompressionLevel.BestCompression, false)) { while ((read = gzip.Read(buffer, 0, BufferSize)) > 0) { output.Write(buffer, 0, read); output.Flush(); } } }
public void TestDotNetZip() { compressor = new Ionic.Zlib.GZipStream(compressed, Ionic.Zlib.CompressionMode.Compress, true); StartCompression(); compressor.Write(input.GetBuffer(), 0, inputSize); compressor.Close(); EndCompression(); var decompressor = new Ionic.Zlib.GZipStream(compressed, Ionic.Zlib.CompressionMode.Decompress, true); decompressor.CopyTo(decompressed); AfterDecompression(); }
public static void ZipStreamCompress(Stream source, Stream dest) { using (var stream = new Ionic.Zlib.GZipStream( dest, Ionic.Zlib.CompressionMode.Compress, Ionic.Zlib.CompressionLevel.BestCompression, true)) { byte[] buf = new byte[ZIP_BUFFER_SIZE]; int len; while ((len = source.Read(buf, 0, buf.Length)) > 0) { stream.Write(buf, 0, len); } } }
public static byte[] DeflateByte(byte[] str) { if (str == null) { return(null); } using (var output = new MemoryStream()) { using (var compressor = new Ionic.Zlib.GZipStream(output, Ionic.Zlib.CompressionMode.Compress, Ionic.Zlib.CompressionLevel.BestSpeed)) { compressor.Write(str, 0, str.Length); } return(output.ToArray()); } }
public static byte[] Decompress(byte[] data) { MemoryStream output = new MemoryStream(); byte[] buffer = new byte[BufferSize]; int read; using (GZipStream gzip = new GZipStream(new MemoryStream(data), CompressionMode.Decompress, CompressionLevel.BestCompression, false)) { while ((read = gzip.Read(buffer, 0, BufferSize)) > 0) { output.Write(buffer, 0, read); } } return output.ToArray(); }
/// <summary>Creates a GZip stream by the given serialized object.</summary> private static Stream CreateGZipStream(string serializedObject) { byte[] bytes = System.Text.Encoding.UTF8.GetBytes(serializedObject); using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) { using (GZipStream gzip = new GZipStream(ms, CompressionMode.Compress, true)) { gzip.Write(bytes, 0, bytes.Length); } // Reset the stream to the beginning. It doesn't work otherwise! ms.Position = 0; byte[] compressed = new byte[ms.Length]; ms.Read(compressed, 0, compressed.Length); return new MemoryStream(compressed); } }
private static async Task CreateResponse( HttpResponse result, Uri uri, HttpRequest request, HttpClientHandler handler, HttpResponseMessage response, CancellationToken token, IProgress <HttpProgress> progress) { if (response.Content != null) { foreach (var header in response.Content.Headers) { result.Headers.Add(header.Key, header.Value.First()); } } foreach (var header in response.Headers) { result.Headers.Add(header.Key, header.Value.First()); } foreach (var cookie in handler.CookieContainer.GetCookies(uri)) { result.Cookies.Add((Cookie)cookie); } var stream = await response.Content.ReadAsStreamAsync(); if (response.Content.Headers.ContentEncoding.Any(e => e.ToLower() == "gzip")) { stream = new Ionic.Zlib.GZipStream(stream, Ionic.Zlib.CompressionMode.Decompress); } else if (response.Content.Headers.ContentEncoding.Any(e => e.ToLower() == "deflate")) { stream = new Ionic.Zlib.DeflateStream(stream, Ionic.Zlib.CompressionMode.Decompress); } if (request.ResponseAsStream) { result.ResponseStream = stream; result.RawResponse = null; } else { result.RawResponse = await stream.ReadToEndAsync( response.Content.Headers.ContentLength.HasValue?response.Content.Headers.ContentLength.Value : -1, token, progress); } }
public override void Execute(object parameter) { var saveFile = new SaveFileDialog { DefaultExt = ".ravendump", Filter = "Raven Dumps|*.ravendump;*.raven.dump", }; var name = ApplicationModel.Database.Value.Name; var normalizedName = new string(name.Select(ch => Path.GetInvalidPathChars().Contains(ch) ? '_' : ch).ToArray()); var defaultFileName = string.Format("Dump of {0}, {1}", normalizedName, DateTimeOffset.Now.ToString("dd MMM yyyy HH-mm", CultureInfo.InvariantCulture)); try { saveFile.DefaultFileName = defaultFileName; } catch { } if (saveFile.ShowDialog() != true) return; taskModel.CanExecute.Value = false; stream = saveFile.OpenFile(); gZipStream = new GZipStream(stream, CompressionMode.Compress); streamWriter = new StreamWriter(gZipStream); jsonWriter = new JsonTextWriter(streamWriter) { Formatting = Formatting.Indented }; taskModel.TaskStatus = TaskStatus.Started; output(String.Format("Exporting to {0}", saveFile.SafeFileName)); output("Begin reading indexes"); jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("Indexes"); jsonWriter.WriteStartArray(); ReadIndexes(0) .Catch(exception => { taskModel.ReportError(exception); Infrastructure.Execute.OnTheUI(() => Finish(exception)); }); }
static public byte[] uncompress(byte[] bytes) { byte[] working = new byte[1024 * 20]; var input = new MemoryStream(bytes); var output = new MemoryStream(); using (Stream decompressor = new GZipStream(input, CompressionMode.Decompress, true)) { int n; while ((n = decompressor.Read(working, 0, working.Length)) != 0) { output.Write(working, 0, n); } } return output.ToArray(); }
public World(String path) { TAG_Compound data; LevelDatPath = path; using (FileStream level = new FileStream(path, FileMode.Open)) { using (GZipStream decompress = new GZipStream(level, CompressionMode.Decompress)) { MemoryStream mem = new MemoryStream(); decompress.CopyTo(mem); mem.Seek(0, SeekOrigin.Begin); data = new TAG_Compound(mem); } } Seed = (long)data["Data"]["RandomSeed"]; OriginalSeed = Seed; Version = (int)data["Data"]["version"]; WorldName = (String)data["Data"]["LevelName"]; WorldDir = Path.GetDirectoryName(path); }
public void GZipStreamTest() { string testString = "Some testing string to compress/decompress using the GzipStream object!"; // compress. var testStringBytes = ASCIIEncoding.ASCII.GetBytes(testString); var compressedStream = new MemoryStream(); var stream = new GZipStream(compressedStream, CompressionMode.Compress); stream.Write(testStringBytes, 0, testStringBytes.Length); stream.Flush(); byte[] compressedTestString = compressedStream.ToArray(); // decompress. compressedStream = new MemoryStream(compressedTestString); var decompressiongStream = new GZipStream(compressedStream, CompressionMode.Decompress); var decompressedStream = new MemoryStream(); decompressiongStream.CopyTo(decompressedStream); var decompressedTestString = new byte[decompressedStream.Length]; decompressedStream.Read(decompressedTestString, 0, decompressedTestString.Length); ASCIIEncoding.ASCII.GetString(decompressedTestString); }
/// <summary> /// 압축된 데이타를 복원한다. /// </summary> /// <param name="input">복원할 Data</param> /// <returns>복원된 Data</returns> public override byte[] Decompress(byte[] input) { if(IsDebugEnabled) log.Debug(CompressorTool.SR.DecompressStartMsg); // check input data if(input.IsZeroLength()) { if(IsDebugEnabled) log.Debug(CompressorTool.SR.InvalidInputDataMsg); return new byte[0]; } byte[] output; var outStream = new MemoryStream(input.Length * 2); try { using(var inStream = new MemoryStream(input)) using(var gzip = new GZipStream(inStream, CompressionMode.Decompress)) { StreamTool.CopyStreamToStream(gzip, outStream, CompressorTool.BUFFER_SIZE); output = outStream.ToArray(); } } catch(Exception ex) { if(log.IsErrorEnabled) log.ErrorException("압축 복원 중 예외가 발생했습니다.", ex); throw; } finally { outStream.Close(); } if(IsDebugEnabled) log.Debug(CompressorTool.SR.DecompressResultMsg, input.Length, output.Length, output.Length / (double)input.Length); return output; }
/// <summary> /// Uncompress a GZip'ed byte array into a single string. /// </summary> /// /// <seealso cref="GZipStream.CompressString(String)"/> /// <seealso cref="GZipStream.UncompressBuffer(byte[])"/> /// /// <param name="compressed"> /// A buffer containing GZIP-compressed data. /// </param> /// /// <returns>The uncompressed string</returns> public static String UncompressString(byte[] compressed) { using (var input = new MemoryStream(compressed)) { Stream decompressor = new GZipStream(input, CompressionMode.Decompress); return ZlibBaseStream.UncompressString(compressed, decompressor); } }
/// <summary> /// Compress a byte array into a new byte array using GZip. /// </summary> /// /// <remarks> /// Uncompress it with <see cref="GZipStream.UncompressBuffer(byte[])"/>. /// </remarks> /// /// <seealso cref="GZipStream.CompressString(string)"/> /// <seealso cref="GZipStream.UncompressBuffer(byte[])"/> /// /// <param name="b"> /// A buffer to compress. /// </param> /// /// <returns>The data in compressed form</returns> public static byte[] CompressBuffer(byte[] b) { using (var ms = new MemoryStream()) { System.IO.Stream compressor = new GZipStream( ms, CompressionMode.Compress, CompressionLevel.BestCompression ); ZlibBaseStream.CompressBuffer(b, compressor); return ms.ToArray(); } }
/// <summary> /// Uncompress a GZip'ed byte array into a byte array. /// </summary> /// /// <seealso cref="GZipStream.CompressBuffer(byte[])"/> /// <seealso cref="GZipStream.UncompressString(byte[])"/> /// /// <param name="compressed"> /// A buffer containing data that has been compressed with GZip. /// </param> /// /// <returns>The data in uncompressed form</returns> public static byte[] UncompressBuffer(byte[] compressed) { using (var input = new System.IO.MemoryStream(compressed)) { System.IO.Stream decompressor = new GZipStream( input, CompressionMode.Decompress ); return ZlibBaseStream.UncompressBuffer(compressed, decompressor); } }
private byte[] Compress(byte[] bytes) { if (this._compression.ToLower() == "gzip") { using (MemoryStream memory = new MemoryStream()) { using (GZipStream gzip = new GZipStream(memory, CompressionMode.Compress, true)) { gzip.Write(bytes, 0, bytes.Length); } return memory.ToArray(); } } if (this._compression.ToLower() == "deflate") { using (MemoryStream memory = new MemoryStream()) { using (ZlibStream deflate = new ZlibStream(memory, CompressionMode.Compress, true)) { deflate.Write(bytes, 0, bytes.Length); } return memory.ToArray(); } } //no compression return bytes; }
void CompressFile(string Source, string Destination) { Log(" Compressing " + Source); bool DeleteSource = false; if( Source == Destination ) { string CopyOrig = Source + ".Copy"; File.Copy(Source, CopyOrig); Source = CopyOrig; DeleteSource = true; } using (System.IO.Stream input = System.IO.File.OpenRead(Source)) { using (var raw = System.IO.File.Create(Destination)) { using (Stream compressor = new Ionic.Zlib.GZipStream(raw, Ionic.Zlib.CompressionMode.Compress,Ionic.Zlib.CompressionLevel.BestCompression)) { byte[] buffer = new byte[2048]; int SizeRead = 0; while ((SizeRead = input.Read(buffer, 0, buffer.Length)) != 0) { compressor.Write(buffer, 0, SizeRead); } } } } if (DeleteSource && File.Exists(Source)) { File.Delete(Source); } }
static void GenUnityMeshs() { Debug.Log("Generating Unity Mesh's"); MapManager.InitializeSolo(); RS2Sharp.Texture.anIntArray1468 = new int[512]; RS2Sharp.Texture.anIntArray1469 = new int[2048]; RS2Sharp.Texture.SINE = new int[2048]; RS2Sharp.Texture.COSINE = new int[2048]; for (int i = 1; i < 512; i++) { RS2Sharp.Texture.anIntArray1468[i] = 32768 / i; } for (int j = 1; j < 2048; j++) { RS2Sharp.Texture.anIntArray1469[j] = 0x10000 / j; } for (int k = 0; k < 2048; k++) { RS2Sharp.Texture.SINE[k] = (int)(65536D * System.Math.Sin((double)k * 0.0030679614999999999D)); RS2Sharp.Texture.COSINE[k] = (int)(65536D * System.Math.Cos((double)k * 0.0030679614999999999D)); } RS2Sharp.Texture.method372(0.80000000000000004D); byte[] gzipInputBuffer = new byte[0]; for (int modelId = 0; modelId < 1000; ++modelId) { byte[] modelData = UnityClient.decompressors[1].decompress(modelId); if (modelData != null) { gzipInputBuffer = new byte[modelData.Length * 100]; int i2 = 0; try { Ionic.Zlib.GZipStream gzipinputstream = new Ionic.Zlib.GZipStream( new MemoryStream(modelData), Ionic.Zlib.CompressionMode.Decompress); do { if (i2 == gzipInputBuffer.Length) { throw new Exception("buffer overflow!"); } int k = gzipinputstream.Read(gzipInputBuffer, i2, gzipInputBuffer.Length - i2); if (k == 0) { break; } i2 += k; } while (true); } catch (IOException _ex) { throw new Exception("error unzipping"); } modelData = new byte[i2]; System.Array.Copy(gzipInputBuffer, 0, modelData, 0, i2); Model model = new Model(modelData, modelId); RuneMesh rMesh = new RuneMesh(); rMesh.Fill(model, true); Mesh mesh = new Mesh(); rMesh.Render(mesh, false); if (mesh.vertexCount > 0) { AssetDatabase.CreateAsset(mesh, "Assets/Resources/Meshes/" + modelId + ".asset"); } } AssetDatabase.SaveAssets(); } }
public static string BuildOBB() { try { var tmpfoler = "/tmp/packs"; GeneralUtils.DeleteDirectory(tmpfoler, true); // mko: cleaning up build folder Directory.CreateDirectory(tmpfoler); var version = "1.0"; try { var parts = PlayerSettings.bundleVersion.Split('.'); version = parts[0] + "." + parts[1]; } catch { } // moko: changed to do a debug dump of all builder job info first var date = System.DateTime.Now.ToString("dd/MM/yy HH:mm"); string header = "*******************************************************************************\n"; header += "Building to " + tmpfoler + " @" + date; Debug.Log(header); Debug.Log("Build Setting Parameters:\n" + BuildSettings.ToString()); Debug.Log("Environment Setting Parameters:\n" + EnvironmentUtils.GetEnvirnomentDetails()); var cl = EnvironmentUtils.Get("BUILD_CL", "0"); PlayerSettings.bundleVersion = version + "." + cl; // step1 build all the bundles (extended bundles) var options = Bundler.BundleOptions.Force | Bundler.BundleOptions.Extended | Bundler.BundleOptions.SkipBase; var packs = Bundler.BuildAll(BuildSettings.BundlerConfigFolder, options); var tarPath = Path.Combine(tmpfoler, "packs.tar"); var packPath = BuildSettings.BuildFolder; var gzipPath = tarPath + ".gz"; var filesPath = Path.Combine(packPath, "files.json"); FileUtil.DeleteFileOrDirectory(filesPath); // calculate the files var files = new Hashtable(); foreach (var packFile in Directory.GetFiles(packPath, "*", SearchOption.AllDirectories)) { var relativeName = packFile.Substring(packPath.Length + 1); var finfo = new FileInfo(packFile); files[relativeName] = finfo.Length; } // write to the files.json var fileData = new Hashtable(); fileData["packs"] = packs; fileData["files"] = files; File.WriteAllBytes(filesPath, EB.Encoding.GetBytes(EB.JSON.Stringify(fileData))); // turn into gz, tar archive using (var gzFile = new FileStream(gzipPath, FileMode.Create, FileAccess.ReadWrite)) { using (var gzStream = new Ionic.Zlib.GZipStream(gzFile, Ionic.Zlib.CompressionMode.Compress, Ionic.Zlib.CompressionLevel.BestCompression)) { var writer = new tar_cs.TarWriter(gzStream); foreach (var packFile in Directory.GetFiles(packPath, "*", SearchOption.AllDirectories)) { var relativeName = packFile.Substring(packPath.Length + 1); //Debug.Log("file: " + relativeName); using (var f = new FileStream(packFile, FileMode.Open, FileAccess.Read)) { writer.Write(f, f.Length, relativeName, string.Empty, string.Empty, 511, System.DateTime.UtcNow); } } writer.Close(); } } //var url = S3Utils.Put(gzipPath, Path.Combine(cl,cl+".obb") ); //return url; return(gzipPath); } catch (System.Exception ex) { Debug.Log("BuildOBB Failed: exception: " + ex.ToString()); throw ex; } }
public static void BuildContentPacksWithOptions(string distList, bool skipBase, bool uploadProduction = false) { try { var tmpfoler = "/tmp/packs"; GeneralUtils.DeleteDirectory(tmpfoler, true); // mko: cleaning up build folder Directory.CreateDirectory(tmpfoler); var version = "1.0"; try { var parts = PlayerSettings.bundleVersion.Split('.'); version = parts[0] + "." + parts[1]; } catch { } var platform = BuildSettings.Target; var date = System.DateTime.Now.ToString("dd/MM/yy HH:mm"); var cl = EnvironmentUtils.Get("BUILD_CL", "0"); var desc = "Content Package " + BuildSettings.Target + " " + date + " CL: " + cl + "\n"; var notes = (ArrayList)EB.JSON.Parse(EnvironmentUtils.Get("BUILD_NOTES", "[]")); PlayerSettings.bundleVersion = version + "." + cl; // step1 build all the bundles (extended bundles) var options = Bundler.BundleOptions.Force | Bundler.BundleOptions.Extended; if (skipBase) { options |= Bundler.BundleOptions.SkipBase; } var packs = Bundler.BuildAll(BuildSettings.BundlerConfigFolder, options); var files = new ArrayList(); foreach (var pack in packs) { var tarPath = Path.Combine(tmpfoler, pack + ".tar"); var packPath = Path.Combine(BuildSettings.BuildFolder, pack); var gzipPath = tarPath + ".gz"; // turn into gz, tar archive using (var gzFile = new FileStream(gzipPath, FileMode.Create, FileAccess.ReadWrite)) { using (var gzStream = new Ionic.Zlib.GZipStream(gzFile, Ionic.Zlib.CompressionMode.Compress, Ionic.Zlib.CompressionLevel.BestCompression)) { var writer = new tar_cs.TarWriter(gzStream); foreach (var packFile in Directory.GetFiles(packPath, "*", SearchOption.AllDirectories)) { var relativeName = packFile.Substring(packPath.Length + 1); //Debug.Log("file: " + relativeName); using (var f = new FileStream(packFile, FileMode.Open, FileAccess.Read)) { writer.Write(f, f.Length, relativeName, string.Empty, string.Empty, 511, System.DateTime.UtcNow); } } writer.Close(); } } var info = new Hashtable(); var size = new FileInfo(gzipPath).Length; info["size"] = size; info["url"] = S3Utils.Put(gzipPath, Path.Combine(cl, Path.GetFileName(gzipPath))); info["md5"] = S3Utils.CalculateMD5(gzipPath); info["pack"] = pack; info["included"] = skipBase; files.Add(info); } // send email var data = new Hashtable(); data["cl"] = int.Parse(cl); data["minVersion"] = int.Parse(cl); data["title"] = desc; data["notes"] = notes; data["files"] = files; data["platform"] = platform; var manifest = EB.JSON.Stringify(data); var manifestUrl = S3Utils.PutData(EB.Encoding.GetBytes(manifest), "manifest.json", Path.Combine(cl, "manifest.json")); data["manifest"] = manifestUrl; if (!string.IsNullOrEmpty(manifestUrl)) { UploadContentManifest(WWWUtils.Environment.LocalTest, manifestUrl, skipBase ? 1 : 0); if (uploadProduction) { UploadContentManifest(WWWUtils.Environment.LocalTest, manifestUrl, skipBase ? 1 : 0); } } Email(distList, "New " + platform + " Content Build: " + cl, File.ReadAllText("Assets/Editor/EB.Core.Editor/Build/Email/contentbuild.txt"), data); Done(); } catch (System.Exception ex) { Debug.Log("BuildContentPacks Failed: exception: " + ex.ToString()); Failed(ex); } ClearProgressBar(); }