public void Download()
        {
            int retries = 0;

            while (retries++ < 3)
            {
                try
                {
                    ArchivePartInfo info = api.DownloadArchivePart(jobId, start, end);

                    Stream      stream      = info.Stream();
                    List <byte> dynamicData = new List <byte>();
                    int         data;
                    long        bytesRead = 0;
                    while ((data = stream.ReadByte()) != -1)
                    {
                        bytesRead = metric.incrementTransferredBytes(1);
                        dynamicData.Add((byte)data);
                    }

                    bucket.Initialize(dynamicData.Count);
                    dynamicData.CopyTo(bucket.Data());

                    using (Stream hashStream = new MemoryStream(bucket.Data(), 0, dynamicData.Count))
                    {
                        string checksum = Amazon.Glacier.TreeHashGenerator.CalculateTreeHash(hashStream);

                        if (checksum != info.Checksum())
                        {
                            metric.removeTransferredBytes(bytesRead);
                            throw new Exception("Checksum mismatch");
                        }

                        bucket.Checksum(checksum);
                        bucket.IsReady(true);

                        metric.incrementTransferredParts();
                    }

                    return;
                }
                catch (Exception e)
                {
                    Console.WriteLine("Downloader Exception: " + e.Message);
                }
            }

            Console.WriteLine("Download failed");
        }
        public ArchivePartInfo DownloadArchivePart(string jobId, long start, long end)
        {
            GetJobOutputRequest downloadRequest = new GetJobOutputRequest()
            {
                JobId     = jobId,
                VaultName = _vault
            };

            downloadRequest.SetRange(start, end);

            GetJobOutputResponse response = _amazonGlacierClient.GetJobOutput(downloadRequest);
            GetJobOutputResult   result   = response.GetJobOutputResult;

            ArchivePartInfo info = new ArchivePartInfo(result.Body, result.Checksum);

            return(info);
        }
Beispiel #3
0
        public ArchivePartInfo DownloadArchivePart(string jobId, long start, long end)
        {
            GetJobOutputRequest downloadRequest = new GetJobOutputRequest()
            {
                JobId = jobId,
                VaultName = _vault
            };

            downloadRequest.SetRange(start, end);

            GetJobOutputResponse response = _amazonGlacierClient.GetJobOutput(downloadRequest);
            GetJobOutputResult result = response.GetJobOutputResult;

            ArchivePartInfo info = new ArchivePartInfo(result.Body, result.Checksum);

            return info;
        }