« Gecko Plugin API Reference « Browser Side Plug-in API
Summary
Pushes data into a stream produced by the plug-in and consumed by the browser.
Syntax
#include <npapi.h> int32 NPN_Write(NPP instance, NPStream* stream, int32 len, void* buf);
Parameters
The function has the following parameters:
-
instance
- Pointer to the current plug-in instance.
-
stream
- Pointer to the stream into which to push the data.
-
len
-
Length in bytes of the data specified by
buf
.
-
buf
- A pointer to a buffer of data to deliver to the stream.
Returns
- If successful, the function returns a positive integer representing the number of bytes written (consumed by the browser). This number depends on the size of the browser's memory buffers, the number of active streams, and other factors.
- If unsuccessful, the plug-in returns a negative integer. This indicates that the browser encountered an error while processing the data, so the plug-in should terminate the stream by calling NPN_DestroyStream().
Description
NPN_Write()
delivers a buffer from the stream to the instance. A plug-in can call this function multiple times after creating a stream with NPN_NewStream(). The browser makes a copy of the buffer if necessary, so the plug-in can free the buffer as the method returns, if desired. See "Example of Sending a Stream" for an example that includes NPN_Write()
.
Example
This example pushes a snippet of HTML over a newly created stream, then destroys the stream when it's done.
NPStream* stream; char* myData = "<HTML><B>This is a message from my plug-in!</B></HTML>"; int32 myLength = strlen(myData) + 1;
/* Create the stream. */
err = NPN_NewStream(instance, "text/html", "_blank", &stream)
/* Push data into the stream. */
err = NPN_Write(instance, stream, myLength, myData);
/* Delete the stream. */
err = NPN_DestroyStream(instance, stream, NPRES_DONE);