Beispiel #1
0
        // Token: 0x06000947 RID: 2375 RVA: 0x0004BB88 File Offset: 0x00049D88
        public Stream Download(INode node, CancellationToken?cancellationToken = null)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }
            if (node.Type != NodeType.File)
            {
                throw new ArgumentException("Invalid node");
            }
            INodeCrypto nodeCrypto = node as INodeCrypto;

            if (nodeCrypto == null)
            {
                throw new ArgumentException("node must implement INodeCrypto");
            }
            this.EnsureLoggedIn();
            DownloadUrlRequest  request             = new DownloadUrlRequest(node);
            DownloadUrlResponse downloadUrlResponse = this.Request <DownloadUrlResponse>(request, null);
            Stream stream = new MegaAesCtrStreamDecrypter(new BufferedStream(this.webClient.GetRequestRaw(new Uri(downloadUrlResponse.Url))), downloadUrlResponse.Size, nodeCrypto.Key, nodeCrypto.Iv, nodeCrypto.MetaMac);

            if (cancellationToken != null)
            {
                stream = new CancellableStream(stream, cancellationToken.Value);
            }
            return(stream);
        }
        /// <summary>
        /// Retrieve a Stream to download and decrypt the specified node
        /// </summary>
        /// <param name="node">Node to download (only <see cref="NodeType.File" /> can be downloaded)</param>
        /// <exception cref="NotSupportedException">Not logged in</exception>
        /// <exception cref="ApiException">Mega.co.nz service reports an error</exception>
        /// <exception cref="ArgumentNullException">node or outputFile is null</exception>
        /// <exception cref="ArgumentException">node is not valid (only <see cref="NodeType.File" /> can be downloaded)</exception>
        /// <exception cref="DownloadException">Checksum is invalid. Downloaded data are corrupted</exception>
        public Stream Download(INode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            if (node.Type != NodeType.File)
            {
                throw new ArgumentException("Invalid node");
            }

            INodeCrypto nodeCrypto = node as INodeCrypto;

            if (nodeCrypto == null)
            {
                throw new ArgumentException("node must implement INodeCrypto");
            }

            this.EnsureLoggedIn();

            // Retrieve download URL
            DownloadUrlRequest  downloadRequest  = new DownloadUrlRequest(node);
            DownloadUrlResponse downloadResponse = this.Request <DownloadUrlResponse>(downloadRequest);

            Stream dataStream = this.webClient.GetRequestRaw(new Uri(downloadResponse.Url));

            return(new MegaAesCtrStreamDecrypter(dataStream, downloadResponse.Size, nodeCrypto.Key, nodeCrypto.Iv, nodeCrypto.MetaMac));
        }
        /// <summary>
        /// Retrieve a Stream to download and decrypt the specified node
        /// </summary>
        /// <param name="node">Node to download (only <see cref="NodeType.File" /> can be downloaded)</param>
        /// <exception cref="NotSupportedException">Not logged in</exception>
        /// <exception cref="ApiException">Mega.co.nz service reports an error</exception>
        /// <exception cref="ArgumentNullException">node or outputFile is null</exception>
        /// <exception cref="ArgumentException">node is not valid (only <see cref="NodeType.File" /> can be downloaded)</exception>
        /// <exception cref="DownloadException">Checksum is invalid. Downloaded data are corrupted</exception>
        public Stream Download(INode node, CancellationToken?cancellationToken = null)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            if (node.Type != NodeType.File)
            {
                throw new ArgumentException("Invalid node");
            }

            INodeCrypto nodeCrypto = node as INodeCrypto;

            if (nodeCrypto == null)
            {
                throw new ArgumentException("node must implement INodeCrypto");
            }

            this.EnsureLoggedIn();

            // Retrieve download URL
            DownloadUrlRequest  downloadRequest  = new DownloadUrlRequest(node);
            DownloadUrlResponse downloadResponse = this.Request <DownloadUrlResponse>(downloadRequest);

            Uri    downloadUrl = new Uri(downloadResponse.Url);
            Stream dataStream  = new SeekableReadStream(this.webClient.GetLength(downloadUrl), (buffer, bufferOffset, offset, count)
                                                        => this.webClient.GetRequestRawWithRange(
                                                            downloadUrl, offset, offset + count).Read(buffer, bufferOffset, count));

            Stream resultStream = new MegaAesCtrStreamDecrypter(dataStream, downloadResponse.Size, nodeCrypto.Key, nodeCrypto.Iv, nodeCrypto.MetaMac);

            if (cancellationToken.HasValue)
            {
                resultStream = new CancellableStream(resultStream, cancellationToken.Value);
            }

            return(resultStream);
        }
Beispiel #4
0
        public Stream Download(INode node, CancellationToken?cancellationToken = null)
#endif
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            if (node.Type != NodeType.File)
            {
                throw new ArgumentException("Invalid node");
            }

            INodeCrypto nodeCrypto = node as INodeCrypto;

            if (nodeCrypto == null)
            {
                throw new ArgumentException("node must implement INodeCrypto");
            }

            this.EnsureLoggedIn();

            // Retrieve download URL
            DownloadUrlRequest  downloadRequest  = new DownloadUrlRequest(node);
            DownloadUrlResponse downloadResponse = this.Request <DownloadUrlResponse>(downloadRequest);

            Stream dataStream = this.webClient.GetRequestRaw(new Uri(downloadResponse.Url));

            Stream resultStream = new MegaAesCtrStreamDecrypter(dataStream, downloadResponse.Size, nodeCrypto.Key, nodeCrypto.Iv, nodeCrypto.MetaMac);

#if !NET35
            if (cancellationToken.HasValue)
            {
                resultStream = new CancellableStream(resultStream, cancellationToken.Value);
            }
#endif
            return(resultStream);
        }