IRandomAccessStream IRandomAccessStream IRandomAccessStream IRandomAccessStream IRandomAccessStream Interface


Supports random access of data in input and output streams.

public : interface IRandomAccessStream : IClosable, IInputStream, IOutputStream
struct winrt::Windows::Storage::Streams::IRandomAccessStream : IClosable, IInputStream, IOutputStream
public interface IRandomAccessStream : IDisposable, IInputStream, IOutputStream
Public Interface IRandomAccessStream Implements IDisposable, IInputStream, IOutputStream
// You can't instantiate an interface directly in JavaScript. You can use objects that implement the interface, however.
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)


For more info, see Quickstart: Reading and writing a file, which shows how to read and write bytes to a file by using a RandomAccessStream. To encode an image by using a stream, see Imaging.


CanRead CanRead CanRead CanRead CanRead

Gets a value that indicates whether the stream can be read from.

public : Platform::Boolean CanRead { get; }
bool CanRead();
public bool CanRead { get; }
Public ReadOnly Property CanRead As bool
var bool = iRandomAccessStream.canRead;
bool bool bool

True if the stream can be read from. Otherwise, false.

CanWrite CanWrite CanWrite CanWrite CanWrite

Gets a value that indicates whether the stream can be written to.

public : Platform::Boolean CanWrite { get; }
bool CanWrite();
public bool CanWrite { get; }
Public ReadOnly Property CanWrite As bool
var bool = iRandomAccessStream.canWrite;
bool bool bool

True if the stream can be written to. Otherwise, false.

Position Position Position Position Position

Gets the byte offset of the stream.

public : ulong Position { get; }
ulong Position();
public ulong Position { get; }
Public ReadOnly Property Position As ulong
var ulong = iRandomAccessStream.position;
ulong ulong ulong

The number of bytes from the start of the stream.


The initial offset of a IRandomAccessStream is 0.

This offset is affected by both IInputStream and IOutputStream operations.

Size Size Size Size Size

Gets or sets the size of the random access stream.

public : ulong Size { get; set; }
ulong Size(); void Size(ulong size);
public ulong Size { get; set; }
Public ReadWrite Property Size As ulong
var ulong = iRandomAccessStream.size;
iRandomAccessStream.size = ulong;
ulong ulong ulong

The size of the stream.


CloneStream() CloneStream() CloneStream() CloneStream() CloneStream()

Creates a new instance of a IRandomAccessStream over the same resource as the current stream.

public : IRandomAccessStream CloneStream()
IRandomAccessStream CloneStream() const;
public IRandomAccessStream CloneStream()
Public Function CloneStream() As IRandomAccessStream
var iRandomAccessStream = iRandomAccessStream.cloneStream();

The new stream. The initial, internal position of the stream is 0.

The internal position and lifetime of this new stream are independent from the position and lifetime of the cloned stream.

Close Close Close Close Close

Releases system resources that are exposed by a Windows Runtime object.

.NET This interface appears as System.IDisposable.

C++/CX This interface appears as Platform::IDisposable.

(Inherited from IClosable)

FlushAsync FlushAsync FlushAsync FlushAsync FlushAsync

Flushes data asynchronously in a sequential stream.

(Inherited from IOutputStream)

GetInputStreamAt(UInt64) GetInputStreamAt(UInt64) GetInputStreamAt(UInt64) GetInputStreamAt(UInt64) GetInputStreamAt(UInt64)

Returns an input stream at a specified location in a stream.

public : IInputStream GetInputStreamAt(unsigned __int64 position)
IInputStream GetInputStreamAt(UInt64 position) const;
public IInputStream GetInputStreamAt(UInt64 position)
Public Function GetInputStreamAt(position As UInt64) As IInputStream
var iInputStream = iRandomAccessStream.getInputStreamAt(position);
UInt64 UInt64 UInt64

The location in the stream at which to begin.


GetOutputStreamAt(UInt64) GetOutputStreamAt(UInt64) GetOutputStreamAt(UInt64) GetOutputStreamAt(UInt64) GetOutputStreamAt(UInt64)

Returns an output stream at a specified location in a stream.

public : IOutputStream GetOutputStreamAt(unsigned __int64 position)
IOutputStream GetOutputStreamAt(UInt64 position) const;
public IOutputStream GetOutputStreamAt(UInt64 position)
Public Function GetOutputStreamAt(position As UInt64) As IOutputStream
var iOutputStream = iRandomAccessStream.getOutputStreamAt(position);
UInt64 UInt64 UInt64

The location in the output stream at which to begin.


ReadAsync(IBuffer,UInt32,InputStreamOptions) ReadAsync(IBuffer,UInt32,InputStreamOptions) ReadAsync(IBuffer,UInt32,InputStreamOptions) ReadAsync(IBuffer,UInt32,InputStreamOptions) ReadAsync(IBuffer,UInt32,InputStreamOptions)

Reads data from the stream asynchronously.

(Inherited from IInputStream)

Seek(UInt64) Seek(UInt64) Seek(UInt64) Seek(UInt64) Seek(UInt64)

Sets the position of the stream to the specified value.

public : void Seek(unsigned __int64 position)
void Seek(UInt64 position) const;
public void Seek(UInt64 position)
Public Function Seek(position As UInt64) As void;
UInt64 UInt64 UInt64

The new position of the stream.



This method does not check the position to make sure the value is valid for the stream. If the position is invalid for the stream, the ReadAsync and WriteAsync methods will return an error if you call them.

WriteAsync(IBuffer) WriteAsync(IBuffer) WriteAsync(IBuffer) WriteAsync(IBuffer) WriteAsync(IBuffer)

Writes data asynchronously in a sequential stream.

(Inherited from IOutputStream)

See Also