Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

ZipPackagePart.cs 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using DocX.iOS.Zip;
  8. namespace System.IO.Packaging
  9. {
  10. public sealed class ZipPackagePart : PackagePart
  11. {
  12. new ZipPackage Package
  13. {
  14. get { return (ZipPackage)base.Package; }
  15. }
  16. internal ZipPackagePart(Package package, Uri partUri)
  17. : base(package, partUri)
  18. {
  19. }
  20. internal ZipPackagePart(Package package, Uri partUri, string contentType)
  21. : base(package, partUri, contentType)
  22. {
  23. }
  24. internal ZipPackagePart(Package package, Uri partUri, string contentType, CompressionOption compressionOption)
  25. : base(package, partUri, contentType, compressionOption)
  26. {
  27. }
  28. protected override Stream GetStreamCore(FileMode mode, FileAccess access)
  29. {
  30. ZipPartStream zps;
  31. MemoryStream stream;
  32. if (Package.PartStreams.TryGetValue(Uri, out stream))
  33. {
  34. //zps = new ZipPartStream(Package, stream, access);
  35. if (mode == FileMode.Create)
  36. stream.SetLength(0);
  37. return new ZipPartStream(Package, stream, access);
  38. }
  39. stream = new MemoryStream();
  40. try
  41. {
  42. if (Package.Archive == null)
  43. {
  44. Package.Archive = ZipStorer.Open(Package.PackageStream, access, false);
  45. }
  46. List<ZipStorer.ZipFileEntry> dir = Package.Archive.ReadCentralDir();
  47. foreach (ZipStorer.ZipFileEntry entry in dir)
  48. {
  49. if (entry.FilenameInZip != Uri.ToString().Substring(1))
  50. continue;
  51. Package.Archive.ExtractFile(entry, stream);
  52. }
  53. }
  54. catch
  55. {
  56. // The zipfile is invalid, so just create the file
  57. // as if it didn't exist
  58. stream.SetLength(0);
  59. }
  60. Package.PartStreams.Add(Uri, stream);
  61. if (mode == FileMode.Create)
  62. stream.SetLength(0);
  63. return new ZipPartStream(Package, stream, access);
  64. }
  65. }
  66. }