Skip to content

Commit 72a4dce

Browse files
committed
Replace SftpFileStream with Stream in ISftpClient method signatures.
1 parent e5ad82c commit 72a4dce

File tree

4 files changed

+47
-47
lines changed

4 files changed

+47
-47
lines changed

src/Renci.SshNet/ISftpClient.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ public interface ISftpClient : IBaseClient
389389
/// </summary>
390390
/// <param name="path">The path and name of the file to create.</param>
391391
/// <returns>
392-
/// A <see cref="SftpFileStream"/> that provides read/write access to the file specified in path.
392+
/// A <see cref="Stream"/> that provides read/write access to the file specified in path.
393393
/// </returns>
394394
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <see langword="null"/>.</exception>
395395
/// <exception cref="SshConnectionException">Client is not connected.</exception>
@@ -398,15 +398,15 @@ public interface ISftpClient : IBaseClient
398398
/// <remarks>
399399
/// If the target file already exists, it is first truncated to zero bytes.
400400
/// </remarks>
401-
SftpFileStream Create(string path);
401+
Stream Create(string path);
402402

403403
/// <summary>
404404
/// Creates or overwrites the specified file.
405405
/// </summary>
406406
/// <param name="path">The path and name of the file to create.</param>
407407
/// <param name="bufferSize">The maximum number of bytes buffered for reads and writes to the file.</param>
408408
/// <returns>
409-
/// A <see cref="SftpFileStream"/> that provides read/write access to the file specified in path.
409+
/// A <see cref="Stream"/> that provides read/write access to the file specified in path.
410410
/// </returns>
411411
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <see langword="null"/>.</exception>
412412
/// <exception cref="SshConnectionException">Client is not connected.</exception>
@@ -415,7 +415,7 @@ public interface ISftpClient : IBaseClient
415415
/// <remarks>
416416
/// If the target file already exists, it is first truncated to zero bytes.
417417
/// </remarks>
418-
SftpFileStream Create(string path, int bufferSize);
418+
Stream Create(string path, int bufferSize);
419419

420420
/// <summary>
421421
/// Creates remote directory specified by path.
@@ -817,59 +817,59 @@ public interface ISftpClient : IBaseClient
817817
IAsyncEnumerable<ISftpFile> ListDirectoryAsync(string path, CancellationToken cancellationToken);
818818

819819
/// <summary>
820-
/// Opens a <see cref="SftpFileStream"/> on the specified path with read/write access.
820+
/// Opens a <see cref="Stream"/> on the specified path with read/write access.
821821
/// </summary>
822822
/// <param name="path">The file to open.</param>
823823
/// <param name="mode">A <see cref="FileMode"/> value that specifies whether a file is created if one does not exist, and determines whether the contents of existing files are retained or overwritten.</param>
824824
/// <returns>
825-
/// An unshared <see cref="SftpFileStream"/> that provides access to the specified file, with the specified mode and read/write access.
825+
/// An unshared <see cref="Stream"/> that provides access to the specified file, with the specified mode and read/write access.
826826
/// </returns>
827827
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <see langword="null"/>.</exception>
828828
/// <exception cref="SshConnectionException">Client is not connected.</exception>
829829
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
830-
SftpFileStream Open(string path, FileMode mode);
830+
Stream Open(string path, FileMode mode);
831831

832832
/// <summary>
833-
/// Opens a <see cref="SftpFileStream"/> on the specified path, with the specified mode and access.
833+
/// Opens a <see cref="Stream"/> on the specified path, with the specified mode and access.
834834
/// </summary>
835835
/// <param name="path">The file to open.</param>
836836
/// <param name="mode">A <see cref="FileMode"/> value that specifies whether a file is created if one does not exist, and determines whether the contents of existing files are retained or overwritten.</param>
837837
/// <param name="access">A <see cref="FileAccess"/> value that specifies the operations that can be performed on the file.</param>
838838
/// <returns>
839-
/// An unshared <see cref="SftpFileStream"/> that provides access to the specified file, with the specified mode and access.
839+
/// An unshared <see cref="Stream"/> that provides access to the specified file, with the specified mode and access.
840840
/// </returns>
841841
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <see langword="null"/>.</exception>
842842
/// <exception cref="SshConnectionException">Client is not connected.</exception>
843843
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
844-
SftpFileStream Open(string path, FileMode mode, FileAccess access);
844+
Stream Open(string path, FileMode mode, FileAccess access);
845845

846846
/// <summary>
847-
/// Asynchronously opens a <see cref="SftpFileStream"/> on the specified path, with the specified mode and access.
847+
/// Asynchronously opens a <see cref="Stream"/> on the specified path, with the specified mode and access.
848848
/// </summary>
849849
/// <param name="path">The file to open.</param>
850850
/// <param name="mode">A <see cref="FileMode"/> value that specifies whether a file is created if one does not exist, and determines whether the contents of existing files are retained or overwritten.</param>
851851
/// <param name="access">A <see cref="FileAccess"/> value that specifies the operations that can be performed on the file.</param>
852852
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to observe.</param>
853853
/// <returns>
854-
/// A <see cref="Task{SftpFileStream}"/> that represents the asynchronous open operation.
855-
/// The task result contains the <see cref="SftpFileStream"/> that provides access to the specified file, with the specified mode and access.
854+
/// A <see cref="Task{Stream}"/> that represents the asynchronous open operation.
855+
/// The task result contains the <see cref="Stream"/> that provides access to the specified file, with the specified mode and access.
856856
/// </returns>
857857
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <see langword="null"/>.</exception>
858858
/// <exception cref="SshConnectionException">Client is not connected.</exception>
859859
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
860-
Task<SftpFileStream> OpenAsync(string path, FileMode mode, FileAccess access, CancellationToken cancellationToken);
860+
Task<Stream> OpenAsync(string path, FileMode mode, FileAccess access, CancellationToken cancellationToken);
861861

862862
/// <summary>
863863
/// Opens an existing file for reading.
864864
/// </summary>
865865
/// <param name="path">The file to be opened for reading.</param>
866866
/// <returns>
867-
/// A read-only <see cref="SftpFileStream"/> on the specified path.
867+
/// A read-only <see cref="Stream"/> on the specified path.
868868
/// </returns>
869869
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <see langword="null"/>.</exception>
870870
/// <exception cref="SshConnectionException">Client is not connected.</exception>
871871
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
872-
SftpFileStream OpenRead(string path);
872+
Stream OpenRead(string path);
873873

874874
/// <summary>
875875
/// Opens an existing UTF-8 encoded text file for reading.
@@ -888,15 +888,15 @@ public interface ISftpClient : IBaseClient
888888
/// </summary>
889889
/// <param name="path">The file to be opened for writing.</param>
890890
/// <returns>
891-
/// An unshared <see cref="SftpFileStream"/> object on the specified path with <see cref="FileAccess.Write"/> access.
891+
/// An unshared <see cref="Stream"/> object on the specified path with <see cref="FileAccess.Write"/> access.
892892
/// </returns>
893893
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <see langword="null"/>.</exception>
894894
/// <exception cref="SshConnectionException">Client is not connected.</exception>
895895
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
896896
/// <remarks>
897897
/// If the file does not exist, it is created.
898898
/// </remarks>
899-
SftpFileStream OpenWrite(string path);
899+
Stream OpenWrite(string path);
900900

901901
/// <summary>
902902
/// Opens a binary file, reads the contents of the file into a byte array, and closes the file.

src/Renci.SshNet/SftpClient.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,7 +1457,7 @@ public StreamWriter AppendText(string path, Encoding encoding)
14571457
/// </summary>
14581458
/// <param name="path">The path and name of the file to create.</param>
14591459
/// <returns>
1460-
/// A <see cref="SftpFileStream"/> that provides read/write access to the file specified in path.
1460+
/// A <see cref="Stream"/> that provides read/write access to the file specified in path.
14611461
/// </returns>
14621462
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <see langword="null"/>.</exception>
14631463
/// <exception cref="SshConnectionException">Client is not connected.</exception>
@@ -1466,7 +1466,7 @@ public StreamWriter AppendText(string path, Encoding encoding)
14661466
/// <remarks>
14671467
/// If the target file already exists, it is first truncated to zero bytes.
14681468
/// </remarks>
1469-
public SftpFileStream Create(string path)
1469+
public Stream Create(string path)
14701470
{
14711471
return Create(path, (int)_bufferSize);
14721472
}
@@ -1477,7 +1477,7 @@ public SftpFileStream Create(string path)
14771477
/// <param name="path">The path and name of the file to create.</param>
14781478
/// <param name="bufferSize">The maximum number of bytes buffered for reads and writes to the file.</param>
14791479
/// <returns>
1480-
/// A <see cref="SftpFileStream"/> that provides read/write access to the file specified in path.
1480+
/// A <see cref="Stream"/> that provides read/write access to the file specified in path.
14811481
/// </returns>
14821482
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <see langword="null"/>.</exception>
14831483
/// <exception cref="SshConnectionException">Client is not connected.</exception>
@@ -1486,7 +1486,7 @@ public SftpFileStream Create(string path)
14861486
/// <remarks>
14871487
/// If the target file already exists, it is first truncated to zero bytes.
14881488
/// </remarks>
1489-
public SftpFileStream Create(string path, int bufferSize)
1489+
public Stream Create(string path, int bufferSize)
14901490
{
14911491
CheckDisposed();
14921492

@@ -1597,72 +1597,72 @@ public DateTime GetLastWriteTimeUtc(string path)
15971597
}
15981598

15991599
/// <summary>
1600-
/// Opens a <see cref="SftpFileStream"/> on the specified path with read/write access.
1600+
/// Opens a <see cref="Stream"/> on the specified path with read/write access.
16011601
/// </summary>
16021602
/// <param name="path">The file to open.</param>
16031603
/// <param name="mode">A <see cref="FileMode"/> value that specifies whether a file is created if one does not exist, and determines whether the contents of existing files are retained or overwritten.</param>
16041604
/// <returns>
1605-
/// An unshared <see cref="SftpFileStream"/> that provides access to the specified file, with the specified mode and read/write access.
1605+
/// An unshared <see cref="Stream"/> that provides access to the specified file, with the specified mode and read/write access.
16061606
/// </returns>
16071607
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <see langword="null"/>.</exception>
16081608
/// <exception cref="SshConnectionException">Client is not connected.</exception>
16091609
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
1610-
public SftpFileStream Open(string path, FileMode mode)
1610+
public Stream Open(string path, FileMode mode)
16111611
{
16121612
return Open(path, mode, FileAccess.ReadWrite);
16131613
}
16141614

16151615
/// <summary>
1616-
/// Opens a <see cref="SftpFileStream"/> on the specified path, with the specified mode and access.
1616+
/// Opens a <see cref="Stream"/> on the specified path, with the specified mode and access.
16171617
/// </summary>
16181618
/// <param name="path">The file to open.</param>
16191619
/// <param name="mode">A <see cref="FileMode"/> value that specifies whether a file is created if one does not exist, and determines whether the contents of existing files are retained or overwritten.</param>
16201620
/// <param name="access">A <see cref="FileAccess"/> value that specifies the operations that can be performed on the file.</param>
16211621
/// <returns>
1622-
/// An unshared <see cref="SftpFileStream"/> that provides access to the specified file, with the specified mode and access.
1622+
/// An unshared <see cref="Stream"/> that provides access to the specified file, with the specified mode and access.
16231623
/// </returns>
16241624
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <see langword="null"/>.</exception>
16251625
/// <exception cref="SshConnectionException">Client is not connected.</exception>
16261626
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
1627-
public SftpFileStream Open(string path, FileMode mode, FileAccess access)
1627+
public Stream Open(string path, FileMode mode, FileAccess access)
16281628
{
16291629
CheckDisposed();
16301630

16311631
return SftpFileStream.Open(_sftpSession, path, mode, access, (int)_bufferSize);
16321632
}
16331633

16341634
/// <summary>
1635-
/// Asynchronously opens a <see cref="SftpFileStream"/> on the specified path, with the specified mode and access.
1635+
/// Asynchronously opens a <see cref="Stream"/> on the specified path, with the specified mode and access.
16361636
/// </summary>
16371637
/// <param name="path">The file to open.</param>
16381638
/// <param name="mode">A <see cref="FileMode"/> value that specifies whether a file is created if one does not exist, and determines whether the contents of existing files are retained or overwritten.</param>
16391639
/// <param name="access">A <see cref="FileAccess"/> value that specifies the operations that can be performed on the file.</param>
16401640
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to observe.</param>
16411641
/// <returns>
1642-
/// A <see cref="Task{SftpFileStream}"/> that represents the asynchronous open operation.
1643-
/// The task result contains the <see cref="SftpFileStream"/> that provides access to the specified file, with the specified mode and access.
1642+
/// A <see cref="Task{Stream}"/> that represents the asynchronous open operation.
1643+
/// The task result contains the <see cref="Stream"/> that provides access to the specified file, with the specified mode and access.
16441644
/// </returns>
16451645
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <see langword="null"/>.</exception>
16461646
/// <exception cref="SshConnectionException">Client is not connected.</exception>
16471647
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
1648-
public Task<SftpFileStream> OpenAsync(string path, FileMode mode, FileAccess access, CancellationToken cancellationToken)
1648+
public async Task<Stream> OpenAsync(string path, FileMode mode, FileAccess access, CancellationToken cancellationToken)
16491649
{
16501650
CheckDisposed();
16511651

1652-
return SftpFileStream.OpenAsync(_sftpSession, path, mode, access, (int)_bufferSize, cancellationToken);
1652+
return await SftpFileStream.OpenAsync(_sftpSession, path, mode, access, (int)_bufferSize, cancellationToken).ConfigureAwait(false);
16531653
}
16541654

16551655
/// <summary>
16561656
/// Opens an existing file for reading.
16571657
/// </summary>
16581658
/// <param name="path">The file to be opened for reading.</param>
16591659
/// <returns>
1660-
/// A read-only <see cref="SftpFileStream"/> on the specified path.
1660+
/// A read-only <see cref="Stream"/> on the specified path.
16611661
/// </returns>
16621662
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <see langword="null"/>.</exception>
16631663
/// <exception cref="SshConnectionException">Client is not connected.</exception>
16641664
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
1665-
public SftpFileStream OpenRead(string path)
1665+
public Stream OpenRead(string path)
16661666
{
16671667
return Open(path, FileMode.Open, FileAccess.Read);
16681668
}
@@ -1687,15 +1687,15 @@ public StreamReader OpenText(string path)
16871687
/// </summary>
16881688
/// <param name="path">The file to be opened for writing.</param>
16891689
/// <returns>
1690-
/// An unshared <see cref="SftpFileStream"/> object on the specified path with <see cref="FileAccess.Write"/> access.
1690+
/// An unshared <see cref="Stream"/> object on the specified path with <see cref="FileAccess.Write"/> access.
16911691
/// </returns>
16921692
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <see langword="null"/>.</exception>
16931693
/// <exception cref="SshConnectionException">Client is not connected.</exception>
16941694
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
16951695
/// <remarks>
16961696
/// If the file does not exist, it is created.
16971697
/// </remarks>
1698-
public SftpFileStream OpenWrite(string path)
1698+
public Stream OpenWrite(string path)
16991699
{
17001700
return Open(path, FileMode.OpenOrCreate, FileAccess.Write);
17011701
}

test/Renci.SshNet.IntegrationTests/SftpTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ public void Sftp_Create_DirectoryDoesNotExist()
256256
client.DeleteFile(remoteFile);
257257
}
258258

259-
SftpFileStream fs = null;
259+
Stream fs = null;
260260

261261
try
262262
{
@@ -4000,8 +4000,8 @@ public void Sftp_SftpFileStream_ReadAndWriteAsyncMemory()
40004000
#endif
40014001

40024002
private void TestReadAndWrite(
4003-
Func<SftpFileStream, byte[], int, int, int> read,
4004-
Action<SftpFileStream, byte[], int, int> write)
4003+
Func<Stream, byte[], int, int, int> read,
4004+
Action<Stream, byte[], int, int> write)
40054005
{
40064006
using (var client = new SftpClient(_connectionInfoFactory.Create()))
40074007
{
@@ -4107,14 +4107,14 @@ private void TestReadAndWrite(
41074107
}
41084108
}
41094109

4110-
int ReadByte(SftpFileStream s)
4110+
int ReadByte(Stream s)
41114111
{
41124112
var buffer = new byte[1];
41134113
var bytesRead = read(s, buffer, 0, 1);
41144114
return bytesRead == 0 ? -1 : buffer[0];
41154115
}
41164116

4117-
void WriteByte(SftpFileStream s, byte b)
4117+
void WriteByte(Stream s, byte b)
41184118
{
41194119
write(s, [b], 0, 1);
41204120
}

0 commit comments

Comments
 (0)