MSStreamReader object

The MSStreamReader object provides methods to asynchronously read an MSStream object, and events to obtain the read results.

Internet Explorer 10

 

Syntax

var reader = new MSStreamReader();

Members

The MSStreamReader object has these types of members:

  • Events
  • Methods
  • Properties

Events

The MSStreamReader object has these events.

Event Description
onabort

ProgressEvent that occurs when a read or creation operation is aborted by calling the abort method.

onerror

ProgressEvent that fires when an error occurs during a read operation by an MSStreamReader or FileReader object.

onload

ProgressEvent that occurs when a read operation by an MSStreamReader or FileReader object successfully completes.

onloadend

ProgressEvent that occurs when a read operation by an MSStreamReader or FileReader object completes, even if the request fails.

onloadstart

ProgressEvent that occurs when a read operation is started by an MSStreamReader or FileReader object.

onprogress

ProgressEvent that occurs when an MSStreamReader or FileReader object reports progress about a read operation.

 

Methods

The MSStreamReader object has these methods.

Method Description
abort

Aborts a read operation by an MSStreamReader or FileReader object.

readAsArrayBuffer

Reads a File, Blob, MSStream into memory as an ArrayBuffer object.

readAsArrayBuffer

This topic replaced by readAsArrayBuffer.

readAsBinaryString

Reads the contents of a MSStream as raw binary.

readAsBlob

Performs an asynchronous read of an MSStream object in order to create a Blob object.

readAsDataURL

This topic replaced by the readAsDataURL topic.

readAsText

Reads a File, Blob, or MSStream object into memory as a text string.

 

Properties

The MSStreamReader object has these properties.

Property Access type Description

error

Read-only

The error that occurred while reading a File, Blob, or MSStream object.

readyState

Contains a constant indicating the current state of the FileReader or MSStreamReader object.

result

The result of the read operation.

 

Remarks

The MSStreamReader constructor returns a new MSStreamReader object.

MSStreamReader lets you read and interact with MSStream objects.

MSStreamReader performs the conversion of multimedia that is in a C++ file format into a format that can be accessed by JavaScript. The original file is accessed as an MSStream that overlays an IInputStream object. The data is converted into a Blob object.

MSStreamReader uses the readAsBlob method to perform an asynchronous read of data from the MSStream when converting it to a Blob. A series of events are used to track the progress of the read and any errors that occur.

The MSStreamReader readyState property can be in one of three states. The readyState returns the current state. The state is one of the following values:

  • EMPTY. The MSStreamReader object has been created and there are no pending reads. This is the default state of a new MSStreamReaderobject, until a read method is called.
  • LOADING. An MSStream is being read. The read operation is running and no error has occurred during the read.
  • DONE. The read operation has completed. The MSStream has been read into memory, an error occurred during the read, or the read was aborted using the abort method. The MSStreamReader is no longer reading an MSStream.

When the MSStreamReader read operation is done on the MSStream, the result property returns the Blob object that contains the data buffered from the MSStream. The result is returned after the loadend event has fired.

Examples

The following shows the code necessary to convert an MSStream to a Blob via MSStreamReader. The myReadAsBlob function in the example assumes that you already have an MSStream object named stream. The MSStreamReader is an asynchronous interface, and was designed to give developers the same coding pattern as is used with FileReader.

//A function that takes an MSStream obtained through XHR or window.msObject:
function myReadAsBlob(stream) {      
  var reader = new MSStreamReader();
  
  // Set up callbacks to handle progress, success, and errors:
  reader.onprogress = updateProgress;
  reader.onload = loaded;
  reader.onerror = errorHandler;

  // Read file into memory:
  reader.readAsBlob(stream);
}

function updateProgress(evt) {
  if (evt.lengthComputable) {
    // evt.loaded and evt.total are ProgressEvent properties.
    var loaded = (evt.loaded / evt.total);
    if (loaded < 1) {
      // Increase the progress bar length.
    }
  }
}

function loaded(evt) {  
  // Obtain the read file data:    
  var blob = evt.target.result;
}

function errorHandler(evt) {
  if(evt.target.error.code != 0) {
    // The stream could not be read.
  }
}