public override IAsyncOperation <IRandomAccessStreamWithContentType> OpenReadAsync() { return(AsyncInfo.Run <IRandomAccessStreamWithContentType>(async(cancellationToken) => { var hFile = NativeFileOperationsHelper.OpenFileForRead(ContainerPath); if (hFile.IsInvalid) { return null; } if (Path == ContainerPath) { return new StreamWithContentType(new FileStream(hFile, FileAccess.Read).AsRandomAccessStream()); } ZipFile zipFile = new ZipFile(new FileStream(hFile, FileAccess.Read)); zipFile.IsStreamOwner = true; var znt = new ZipNameTransform(ContainerPath); var entry = zipFile.GetEntry(znt.TransformFile(Path)); if (entry != null) { var nsStream = new NonSeekableRandomAccessStream(zipFile.GetInputStream(entry), (ulong)entry.Size) { DisposeCallback = () => zipFile.Close() }; return new StreamWithContentType(nsStream); } return null; })); }
public override IAsyncOperation <IRandomAccessStreamWithContentType> OpenReadAsync() { return(AsyncInfo.Run <IRandomAccessStreamWithContentType>(async(cancellationToken) => { var ftpClient = new FtpClient(); ftpClient.Host = FtpHelpers.GetFtpHost(Path); ftpClient.Port = FtpHelpers.GetFtpPort(Path); ftpClient.Credentials = FtpManager.Credentials.Get(ftpClient.Host, FtpManager.Anonymous); if (!await ftpClient.EnsureConnectedAsync()) { return null; } var inStream = await ftpClient.OpenReadAsync(FtpPath, cancellationToken); var nsStream = new NonSeekableRandomAccessStream(inStream, (ulong)inStream.Length) { DisposeCallback = () => ftpClient.Dispose() }; return new StreamWithContentType(nsStream); })); }