GetObjectBytesResult.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. namespace COSXML.Model.Object
  5. {
  6. public sealed class GetObjectBytesResult : CosResult
  7. {
  8. public string eTag;
  9. public byte[] content;
  10. private COSXML.Callback.OnProgressCallback progressCallback;
  11. internal override void ExternInfo(CosRequest cosRequest)
  12. {
  13. base.ExternInfo(cosRequest);
  14. GetObjectBytesRequest getObjectBytesRequest = cosRequest as GetObjectBytesRequest;
  15. this.progressCallback = getObjectBytesRequest.GetCosProgressCallback();
  16. }
  17. internal override void InternalParseResponseHeaders()
  18. {
  19. List<string> values;
  20. this.responseHeaders.TryGetValue("ETag", out values);
  21. if (values != null && values.Count > 0)
  22. {
  23. eTag = values[0];
  24. }
  25. }
  26. internal override void ParseResponseBody(Stream inputStream, string contentType, long contentLength)
  27. {
  28. content = new byte[contentLength];
  29. int completed = 0;
  30. while (completed < contentLength)
  31. {
  32. int recvLen = inputStream.Read(content, completed, (int)Math.Min(2048, contentLength - completed));
  33. completed += recvLen;
  34. if (progressCallback != null)
  35. {
  36. progressCallback(completed, content.Length);
  37. }
  38. }
  39. // Unity 上不支持
  40. // using(var memoryStream = new MemoryStream())
  41. // {
  42. // inputStream.CopyTo(memoryStream);
  43. // content = memoryStream.ToArray();
  44. // }
  45. }
  46. }
  47. }