OpenAsync() public static method

public static OpenAsync ( IRBlobInfo blobInfo, IRBlobService blobService, CancellationToken ct = default(CancellationToken) ) : Task
blobInfo IRBlobInfo
blobService IRBlobService
ct System.Threading.CancellationToken
return Task
Example #1
0
        /// <summary>
        /// Gets the data for a given blob from R-Host. Saves the data to <paramref name="filePath"/>. This
        /// method adds the blob for clean up by default.
        /// </summary>
        /// <param name="blob">Blob from which the data is to be retrieved.</param>
        /// <param name="filePath">Path to the file where the retrieved data will be written.</param>
        /// <param name="doCleanUp">true to add blob upon transfer for cleanup on dispose, false to ignore it after transfer.</param>
        public async Task FetchFileAsync(IRBlobInfo blob, string filePath, bool doCleanUp, IProgress <long> progress, CancellationToken cancellationToken)
        {
            using (RBlobStream blobStream = await RBlobStream.OpenAsync(blob, _blobService))
                using (Stream fileStream = _fs.CreateFile(filePath)) {
                    await blobStream.CopyToAsync(fileStream, progress, cancellationToken);
                }

            if (doCleanUp)
            {
                _cleanup.Add(blob);
            }
        }
Example #2
0
        /// <summary>
        /// Gets contents of a remote file and copies it to given stream. This method adds the blob for clean up by default.
        /// </summary>
        /// <param name="remoteFile"></param>
        /// <param name="stream"></param>
        /// <param name="doCleanUp"></param>
        public async Task CopyToFileStreamAsync(string remoteFile, Stream stream, bool doCleanUp = true, IProgress <long> progress = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            string     filePath = remoteFile.ToRPath().ToRStringLiteral();
            IRBlobInfo blob     = new RBlobInfo(await _session.EvaluateAsync <ulong>($"rtvs:::create_blob(readBin({filePath}, 'raw', file.info({filePath})$size))", REvaluationKind.Normal, cancellationToken));

            using (RBlobStream blobStream = await RBlobStream.OpenAsync(blob, _blobService, cancellationToken)) {
                await blobStream.CopyToAsync(stream, progress, cancellationToken);
            }

            if (doCleanUp)
            {
                _cleanup.Add(blob);
            }
        }
Example #3
0
        /// <summary>
        /// Gets the data for a given blob from R-Host. This method adds the blob for clean up by default.
        /// </summary>
        /// <param name="blob">Blob from which the data is to be retrieved.</param>
        /// <param name="doCleanUp">true to add blob upon transfer for cleanup on dispose, false to ignore it after transfer.</param>
        public async Task <byte[]> FetchBytesAsync(IRBlobInfo blob, bool doCleanUp, IProgress <long> progress, CancellationToken cancellationToken)
        {
            byte[] data = null;
            using (RBlobStream blobStream = await RBlobStream.OpenAsync(blob, _blobService, cancellationToken))
                using (MemoryStream ms = new MemoryStream((int)blobStream.Length)) {
                    await blobStream.CopyToAsync(ms, progress, cancellationToken);

                    data = ms.ToArray();
                }

            if (doCleanUp)
            {
                _cleanup.Add(blob);
            }

            return(data);
        }