Creates random access data (Blob) from an MSStream object.
Syntax
var reader = new MSStreamReader();
Members
The MSStreamReader object has these types of members:
Events
The MSStreamReader object has these events.
| Event | Description |
|---|---|
| onabort |
Fires when a read or creation operation is aborted by calling the abort method. |
| onerror |
Fires when an error occurs when using the msStreamReader or FileReader object. |
| onload |
Fires when the creation of, or read by, an msStreamReader or FileReader object successfully completes. |
| onloadend |
Fires when the request to create or read an msStreamReader or FileReader object completes, even if the request fails. |
| onloadstart |
Fires at the start of the creation of, or read by, an msStreamReader or FileReader object. |
| onprogress |
Contains a function pointer to the |
Methods
The MSStreamReader object has these methods.
| Method | Description |
|---|---|
| abort |
Aborts a read operation by an MSStreamReader or FileReader object. |
| readAsArrayBuffer |
Reads a MSStreamReader into memory as an array buffer. |
| readAsBlob |
Performs an asynchronous read of an MSStream object in order to create a Blob object. |
| readAsDataURL |
Reads a MSStreamReader object into memory as a data URL string. |
| readAsText |
Reads a MSStreamReader object into memory as a text string. |
Properties
The MSStreamReader object has these properties.
| Property | Description |
|---|---|
|
The error that occurred while reading the file. | |
|
Contains a constant indicating the current state of the FileReader/msStreamReader object. | |
|
The result of the read operation. |
Remarks
MSStreamReader is a constructor function producing an object that provides methods to asynchronously read an MSStream, and an event model to obtain the results of these reads.
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 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 the readAsBlob method is called.
- LOADING. An MSStream is being read. The readAsBlob method is running and no error has occurred during the read.
- DONE. The entire MSStream has been read into memory, a file error occurred during the read, or the read was aborted using the abort method. The MSStreamReader is no longer reading an MSStream. If readyState is set to
DONE, it means that the readAsBlob method has been called at least once.
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 onloadend event has fired.
Examples
The following shows the code necessary to convert an MSStream to a
Blob via StreamReader. The myReadAsBlob function in the example assumes that you already have an MSStream
object named stream. The StreamReader 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. } }
Build date: 11/28/2012