Changes for page Download a project (export)
Last modified by Robert Jan Daams on 2025/03/05 18:02
Change comment:
Update document after refactoring.
Summary
-
Page properties (2 modified, 0 added, 0 removed)
Details
- Page properties
-
- Title
-
... ... @@ -1,1 +1,1 @@ 1 - Downloadaproject(export)1 +Setting up a Webservice connection for project exports - Content
-
... ... @@ -408,7 +408,137 @@ 408 408 </soap:Envelope> 409 409 {{/code}} 410 410 411 - 411 + 412 +== Zip Stream class == 413 + 414 +If needed, this is the Zip Stream class you can use to extract the zipstream as used above: 415 + 416 +{{code language="Csharp" layout="LINENUMBERS"}} 417 +/// <summary> 418 +/// Helper class for compress en decompress of file data 419 +/// </summary> 420 +public static class ZipStreamHelper { 421 + #region Compress and encode 422 + /// <summary> 423 + /// Comprimeer een string en geeft deze terug in Base64 string. 424 + /// </summary> 425 + /// <param name="content">filecontent</param> 426 + /// <returns>gecomprimeerde string</returns> 427 + public static string CompressToBase64String(string content) { 428 + //string to byte[] 429 + byte[] contentArray = stringToByteArray(content); 430 + // Compress 431 + byte[] compressed = Compress(contentArray); 432 + return base64_encode(compressed); 433 + } 434 + 435 + /// <summary> 436 + /// Zet een string om naar een ByteArray 437 + /// </summary> 438 + /// <param name="content">filecontent</param> 439 + /// <returns>ByteArray</returns> 440 + public static byte[] stringToByteArray(string content) { 441 + System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding(); 442 + return encoding.GetBytes(content); 443 + } 444 + 445 + /// <summary> 446 + /// comprimeer een ByteArray 447 + /// </summary> 448 + /// <param name="data">filedata als ByteArray</param> 449 + /// <returns>gecomprimeerde ByteArray</returns> 450 + public static byte[] Compress(byte[] data) { 451 + using(var compressedStream = new MemoryStream()) 452 + using(var zipStream = new GZipStream(compressedStream, CompressionMode.Compress)) { 453 + zipStream.Write(data, 0, data.Length); 454 + zipStream.Close(); 455 + return compressedStream.ToArray(); 456 + } 457 + } 458 + 459 + /// <summary> 460 + /// Zet een ByteArray om naar een Base64 string 461 + /// </summary> 462 + /// <param name="data">gecomprimeerde ByteArray</param> 463 + /// <returns>Base 64 string</returns> 464 + public static string base64_encode(byte[] data) { 465 + if (data == null) 466 + return string.Empty; 467 + return Convert.ToBase64String(data); 468 + } 469 + 470 + /// <summary> 471 + /// Zet een string om naar een Base64 string 472 + /// </summary> 473 + /// <param name="data">string</param> 474 + /// <returns>Base 64 string</returns> 475 + public static string string_base64_encode(string data) { 476 + if (string.IsNullOrEmpty(data)) 477 + return string.Empty; 478 + 479 + //string to byte[] 480 + byte[] contentArray = stringToByteArray(data); 481 + return base64_encode(contentArray); 482 + } 483 + #endregion 484 + 485 + #region Decompress and decode 486 + // Decode and decompress 487 + /// <summary> 488 + /// Decomprimeer een Base64 string naar een string 489 + /// </summary> 490 + /// <param name="contentBase64">GZIP Base64 string</param> 491 + /// <returns>string</returns> 492 + public static string DecompressBase64StringToString(string contentBase64) { 493 + // Decompress 494 + byte[] decoded = base64_decode(contentBase64); 495 + byte[] decompressed = Decompress(decoded); 496 + 497 + return byteArrayTostring(decompressed); 498 + } 499 + 500 + /// <summary> 501 + /// Zet een ByteArray om in een normale string 502 + /// </summary> 503 + /// <param name="data">ByteArray</param> 504 + /// <returns>string</returns> 505 + public static string byteArrayTostring(byte[] data) { 506 + System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding(); 507 + return enc.GetString(data); 508 + } 509 + 510 + /// <summary> 511 + /// Zet een Base64 string om naar een ByteArray 512 + /// </summary> 513 + /// <param name="encodedData">Base64 string</param> 514 + /// <returns>gecomprimeerde ByteArray</returns> 515 + public static byte[] base64_decode(string encodedData) { 516 + byte[] encodedDataAsBytes = Convert.FromBase64String(encodedData); 517 + return encodedDataAsBytes; 518 + } 519 + 520 + /// <summary> 521 + /// Zet een gecomprimeerde ByteArray om in een ByteArray 522 + /// </summary> 523 + /// <param name="data">gecomprimeerde ByteArray</param> 524 + /// <returns>ByteArray (gedecomprimeerd)</returns> 525 + public static byte[] Decompress(byte[] data) { 526 + using(var compressedStream = new MemoryStream(data)) 527 + using(var zipStream = new GZipStream(compressedStream, CompressionMode.Decompress)) 528 + using(var resultStream = new MemoryStream()) { 529 + var buffer = new byte[4096]; 530 + int read; 531 + 532 + while ((read = zipStream.Read(buffer, 0, buffer.Length)) > 0) { 533 + resultStream.Write(buffer, 0, read); 534 + } 535 + 536 + return resultStream.ToArray(); 537 + } 538 + } 539 + #endregion 540 +} 541 +{{/code}} 412 412 ))) 413 413 414 414