Task <IStorageStream> GetWriteStream(string identifier)
        {
            string fullPath = GetAbsolutePath(identifier);

#if !UNITY_EDITOR && (UNITY_WSA || UNITY_WINRT)
            identifier = identifier.Replace('/', '\\');
            fullPath   = fullPath.Replace('/', '\\');
#endif

#if !UNITY_EDITOR && (UNITY_WSA || UNITY_WINRT)
            StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(this.BasePath.Replace('/', '\\'));

            // Ensure directory exists
            string folderName = Path.GetDirectoryName(identifier);
            if (!string.IsNullOrEmpty(folderName))
            {
                folder = await folder.CreateFolderAsync(folderName, CreationCollisionOption.OpenIfExists);
            }
            Stream file = await folder.OpenStreamForWriteAsync(Path.GetFileName(identifier) + this.TemporarySuffix, CreationCollisionOption.OpenIfExists);

            FileStorageStream storageStream = new FileStorageStream(fullPath, identifier, file);
            return(storageStream);
#else
            try
            {
                // Ensure directory exists
                Directory.CreateDirectory(Path.GetDirectoryName(fullPath));
                FileStream        file          = File.Open(fullPath + this.TemporarySuffix, FileMode.Create);
                FileStorageStream storageStream = new FileStorageStream(fullPath, identifier, file);
                return(Task.FromResult <IStorageStream>(storageStream));
            }
            catch (Exception ex)
            {
                if (ex is FileNotFoundException)
                {
                    throw new StorageItemNotFoundException(identifier, ex);
                }
                if (ex is NotSupportedException || ex is PathTooLongException || ex is ArgumentException || ex is ArgumentNullException)
                {
                    throw new StorageInvalidIdentifierException(identifier, ex);
                }
                throw;
            }
#endif
        }
        Task CommitWriteStreamInternal(IStorageStream stream)
        {
            FileStorageStream fileStream = (FileStorageStream)stream;

#if !UNITY_EDITOR && (UNITY_WSA || UNITY_WINRT)
            stream.UnderlyingStream.Close();
            StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(this.BasePath.Replace('/', '\\'));

            string folderName = Path.GetDirectoryName(stream.Identifier);
            if (!string.IsNullOrEmpty(folderName))
            {
                folder = await folder.GetFolderAsync(folderName);
            }
            StorageFile tempFile = await folder.GetFileAsync(Path.GetFileName(stream.Identifier) + this.TemporarySuffix);

            await tempFile.RenameAsync(Path.GetFileName(stream.Identifier), NameCollisionOption.ReplaceExisting);
#else
            File.Delete(fileStream.FullPath);
            File.Move(fileStream.FullPath + this.TemporarySuffix, fileStream.FullPath);
            return(Task.CompletedTask);
#endif
        }