mozilla

Revision 90522 of NPN_Write

  • Revision slug: NPN_Write
  • Revision title: NPN_Write
  • Revision id: 90522
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment 136 words added

Revision Content

{{ Np-browser-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.

Note: You should actually handle errors, which this example doesn't do.
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);

See also

Revision Source

<p>{{ Np-browser-api() }}</p>
<h3 id="Summary" name="Summary">Summary</h3>
<p>Pushes data into a stream produced by the plug-in and consumed by the browser.</p>
<h3 id="Syntax" name="Syntax">Syntax</h3>
<pre>#include &lt;npapi.h&gt;
 
int32 NPN_Write(NPP instance, 
          NPStream* stream,
          int32     len,
          void*     buf);
</pre>
<h3 id="Parameters" name="Parameters">Parameters</h3>
<p>The function has the following parameters:</p>
<dl> <dt><code>instance</code></dt> <dd>Pointer to the current plug-in instance.</dd>
</dl>
<dl> <dt><code>stream</code></dt> <dd>Pointer to the stream into which to push the data.</dd>
</dl>
<dl> <dt><code>len</code></dt> <dd>Length in bytes of the data specified by <code>buf</code>.</dd>
</dl>
<dl> <dt><code>buf</code></dt> <dd>A pointer to a buffer of data to deliver to the stream.</dd>
</dl>
<h3 id="Returns" name="Returns">Returns</h3>
<ul> <li>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.</li> <li>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 <a href="/en/NPN_DestroyStream" title="en/NPN_DestroyStream">NPN_DestroyStream()</a>.</li>
</ul>
<h3 id="Description" name="Description">Description</h3>
<p><code>NPN_Write()</code> delivers a buffer from the stream to the instance. A plug-in can call this function multiple times after creating a stream with <a href="/en/NPN_NewStream" title="en/NPN_NewStream">NPN_NewStream()</a>. 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 <code>NPN_Write()</code>.</p>
<h3 id="Example">Example</h3>
<p>This example pushes a snippet of HTML over a newly created stream, then destroys the stream when it's done.</p>
<div class="note"><strong>Note:</strong> You should actually handle errors, which this example doesn't do.</div>
<pre class="brush: cpp">NPStream* stream;
 
char* myData = "&lt;HTML&gt;&lt;B&gt;This is a message from my plug-in!&lt;/B&gt;&lt;/HTML&gt;";
int32 myLength = strlen(myData) + 1; <p><br>/* Create the stream. */<br> <br>err = NPN_NewStream(instance, "text/html", "_blank", &amp;stream)<br><br>/* Push data into the stream. */<br> <br>err = NPN_Write(instance, stream, myLength, myData);<br><br>/* Delete the stream. */<br> <br>err = NPN_DestroyStream(instance, stream, NPRES_DONE);</p></pre>
<h3 id="See_Also" name="See_Also">See also</h3>
<ul> <li><a href="/en/NPP_NewStream" title="en/NPP_NewStream">NPP_NewStream()</a></li> <li><a href="/en/NPP_DestroyStream" title="en/NPP_DestroyStream">NPP_DestroyStream()</a></li> <li><a href="/en/NPP_Read" title="en/NPP Read">NPP_Read()</a></li> <li><a href="/en/NPStream" title="en/NPStream">NPStream</a></li> <li><a href="/en/NPP" title="en/NPP">NPP</a></li>
</ul>
Revert to this revision