示例#1
0
        public override long Seek(long offset, SeekOrigin origin)
        {
            _options.Dispose();
            _result.Dispose();

            switch (origin)
            {
            case SeekOrigin.End:
                Position = Length + offset;
                break;

            case SeekOrigin.Begin:
                Position = offset;
                break;

            case SeekOrigin.Current:
                Position += offset;
                break;

            default:
                throw new NotSupportedException();
            }

            _options = new SWIG.UplinkDownloadOptions {
                length = _length, offset = Position
            };
            _result = SWIG.storj_uplink.uplink_download_object(_bucket._projectRef, _bucket.Name, _objectName, _options);

            return(Position);
        }
示例#2
0
 internal DownloadOperation(SWIG.UplinkDownloadResult downloadResult, long totalBytes, string objectName)
 {
     _download        = downloadResult.download;
     TotalBytes       = totalBytes;
     _bytesToDownload = new byte[TotalBytes];
     ObjectName       = objectName;
 }
示例#3
0
        public async Task <DownloadOperation> DownloadObjectAsync(Bucket bucket, string targetPath, DownloadOptions downloadOptions, bool immediateStart = true)
        {
            using (var downloadOptionsSWIG = downloadOptions.ToSWIG())
            {
                using (SWIG.UplinkDownloadResult downloadResult = await Task.Run(() => SWIG.storj_uplink.uplink_download_object(_access._project, bucket.Name, targetPath, downloadOptionsSWIG)))
                {
                    if (downloadResult.error != null && !string.IsNullOrEmpty(downloadResult.error.message))
                    {
                        throw new ObjectNotFoundException(targetPath, downloadResult.error.message);
                    }

                    using (SWIG.UplinkObjectResult objectResult = await Task.Run(() => SWIG.storj_uplink.uplink_download_info(downloadResult.download)))
                    {
                        if (objectResult.error != null && !string.IsNullOrEmpty(objectResult.error.message))
                        {
                            throw new ObjectNotFoundException(targetPath, objectResult.error.message);
                        }

                        DownloadOperation download = new DownloadOperation(downloadResult, objectResult.object_.system.content_length, targetPath);
                        if (immediateStart)
                        {
                            download.StartDownloadAsync(); //Don't await it, otherwise it would "block" DownloadObjectAsync
                        }
                        return(download);
                    }
                }
            }
        }
示例#4
0
 public void Dispose()
 {
     if (_downloadResult != null)
     {
         SWIG.storj_uplink.uplink_free_download_result(_downloadResult);
         _downloadResult.Dispose();
         _downloadResult = null;
     }
 }
示例#5
0
 public DownloadStream(Bucket bucket, int totalBytes, string objectName)
 {
     _length     = totalBytes;
     _bucket     = bucket;
     _objectName = objectName;
     _options    = new SWIG.UplinkDownloadOptions {
         length = totalBytes, offset = Position
     };
     _result = SWIG.storj_uplink.uplink_download_object(_bucket._projectRef, _bucket.Name, _objectName, _options);
 }
示例#6
0
 protected override void Dispose(bool disposing)
 {
     if (_options != null)
     {
         _options.Dispose();
         _options = null;
     }
     if (_result != null)
     {
         _result.Dispose();
         _result = null;
     }
 }