Exemple #1
0
        protected static async Task BigFileAppendUploadDownLoad()
        {
            var         temp        = Enumerable.Repeat((byte)99, 1024 * 1024 * 100);
            var         testBytes   = temp.ToArray();
            StorageNode storageNode = await FastDFSClient.GetStorageNodeAsync("group1", "default");


            var filename = await FastDFSClient.UploadAppenderFileAsync(storageNode, testBytes.Take(1024 * 1024 * 2).ToArray(), "txt", "default");

            for (int i = 0; i < 49; i++)
            {
                FDFSFileInfo fileInfo = await FastDFSClient.GetFileInfoAsync(storageNode, filename, "default");

                var appendBytes = testBytes.Skip((int)fileInfo.FileSize).Take(1024 * 1024 * 2).ToArray();
                await FastDFSClient.AppendFileAsync("group1", filename, appendBytes, "default");
            }

            using (var fileStream = File.OpenWrite("c:\\fastdfs_test.txt"))
            {
                for (int i = 0; i < 50; i++)
                {
                    var buffer = await FastDFSClient.DownloadFileAsync(storageNode, filename, "default",
                                                                       1024 * 1024 * 2 *i,
                                                                       1024 * 1024 * 2);

                    fileStream.Write(buffer, 0, buffer.Length);
                }
            }

            await FastDFSClient.RemoveFileAsync("group1", filename, "default");

            temp      = null;
            testBytes = null;
        }
Exemple #2
0
        private static async Task UploadAppendFile()
        {
            var         testBytes   = Encoding.UTF8.GetBytes("123456789");
            StorageNode storageNode = await FastDFSClient.GetStorageNodeAsync("group1", "server");

            var filename = await FastDFSClient.UploadAppenderFileAsync(storageNode, testBytes.Take(6).ToArray(), "", "default");

            FDFSFileInfo fileInfo = await FastDFSClient.GetFileInfoAsync(storageNode, filename, "default");

            if (fileInfo == null)
            {
                Console.WriteLine($"GetFileInfoAsync Fail, path: {filename}");
                return;
            }

            Console.WriteLine("FileName:{0}", filename);
            Console.WriteLine("FileSize:{0}", fileInfo.FileSize);
            Console.WriteLine("CreateTime:{0}", fileInfo.CreateTime);
            Console.WriteLine("Crc32:{0}", fileInfo.Crc32);

            var appendBytes = testBytes.Skip((int)fileInfo.FileSize).ToArray();
            await FastDFSClient.AppendFileAsync("group1", filename, appendBytes, "default");

            var test = await HttpClient.GetByteArrayAsync(StorageLink + filename);

            if (Encoding.UTF8.GetString(test) == Encoding.UTF8.GetString(testBytes))
            {
                Console.WriteLine($"UploadAppendFile Success");
            }
            else
            {
                throw new ApplicationException($"UploadAppendFile Fail : Bytes Diff ");
            }
            await FastDFSClient.RemoveFileAsync("group1", filename, "default");
        }