OssObject.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (C) Alibaba Cloud Computing
  3. * All rights reserved.
  4. *
  5. * 版权所有 (C)阿里云计算有限公司
  6. */
  7. using System;
  8. using System.Globalization;
  9. using System.IO;
  10. namespace Aliyun.OSS
  11. {
  12. /// <summary>
  13. /// 表示OSS中的Object。
  14. /// </summary>
  15. /// <remarks>
  16. /// <para>
  17. /// 在 OSS 中,用户的每个文件都是一个 Object,每个文件需小于 5G。
  18. /// Object包含key、data和user meta。其中,key是Object 的名字;
  19. /// data是Object 的数据;user meta是用户对该object的描述。
  20. /// </para>
  21. /// </remarks>
  22. public class OssObject : IDisposable
  23. {
  24. private bool _disposed;
  25. /// <summary>
  26. /// 获取或设置Object的Key。
  27. /// </summary>
  28. public string Key { get; internal set; }
  29. /// <summary>
  30. /// 获取或设置Object所在<see cref="Bucket" />的名称。
  31. /// </summary>
  32. public string BucketName { get; internal set; }
  33. /// <summary>
  34. /// 获取Object的元数据。
  35. /// </summary>
  36. public ObjectMetadata Metadata { get; internal set; }
  37. /// <summary>
  38. /// 获取或设置Object内容的数据流。
  39. /// </summary>
  40. public Stream Content { get; internal set; }
  41. /// <summary>
  42. /// 构造一个新的<see cref="OssObject" />实例。
  43. /// </summary>
  44. internal OssObject()
  45. { }
  46. /// <summary>
  47. /// 构造一个新的<see cref="OssObject" />实例。
  48. /// </summary>
  49. internal OssObject(string key)
  50. {
  51. Key = key;
  52. }
  53. public override string ToString()
  54. {
  55. return string.Format(CultureInfo.InvariantCulture,
  56. "[OSSObject Key={0}, targetBucket={1}]", Key, BucketName ?? string.Empty);
  57. }
  58. /// <summary>
  59. /// 释放<see cref="OssObject.Content" />。
  60. /// </summary>
  61. public void Dispose()
  62. {
  63. Dispose(true);
  64. GC.SuppressFinalize(this);
  65. }
  66. protected virtual void Dispose(bool disposing)
  67. {
  68. if (!_disposed)
  69. {
  70. if (Content != null)
  71. Content.Dispose();
  72. _disposed = true;
  73. }
  74. }
  75. }
  76. }