예제 #1
0
        public async Task Copy(string asset)
        {
            System.IO.Stream source          = openAsset(asset);
            File             destinationFile = new File(externalDir, asset);

            destinationFile.ParentFile.Mkdir();

            OutputStream destination = new FileOutputStream(destinationFile);

            byte[] buffer = new byte[1024];
            int    nread;

            System.Diagnostics.Debug.WriteLine(this.GetType().Name, $"Copying asset {destinationFile} to {asset}");

            while ((nread = await source.ReadAsync(buffer, 0, buffer.Length)) > 0)
            {
                await destination.WriteAsync(buffer, 0, nread);

                await destination.FlushAsync();
            }

            destination.Close();

            System.Diagnostics.Debug.WriteLine(this.GetType().Name, $"DONE! Copied asset {asset} to {destinationFile}");
        }
예제 #2
0
        public async Task <File> Copy(string asset)
        {
            System.IO.Stream source          = openAsset(asset);
            File             destinationFile = new File(externalDir, asset);

            destinationFile.ParentFile.Mkdir();

            OutputStream destination = new FileOutputStream(destinationFile);

            byte[] buffer = new byte[1024];
            int    nread;

            while ((nread = await source.ReadAsync(buffer, 0, buffer.Length)) > 0)
            {
                await destination.WriteAsync(buffer, 0, nread);

                await destination.FlushAsync();
            }

            destination.Close();

            return(destinationFile);
        }