return NS_OK;
if (numtowrite > 0) { #if 0 printf(">  %d - %d \n", sourceOffset + writeCount + mPosition, numtowrite); nsCString x; x.Append("d:\\parts\\"); x.AppendInt(sourceOffset);  PRFileDesc* fd; fd = PR_Open(x, PR_CREATE_FILE |PR_SYNC| PR_APPEND | PR_RDWR, 777); PR_Write(fd, mStreamBuffer, numtowrite); PR_Close(fd); #endif  NS_TRY_SAFE_CALL_RETURN(writeCount, CallNPP_WriteProc(callbacks->write, npp, &mNPStream, sourceOffset + writeCount + mPosition, numtowrite, (void *)mStreamBuffer), mInst->fLibrary);  NPP_PLUGIN_LOG(PLUGIN_LOG_NOISY, ("NPP Write called: this=%p, npp=%p, pos=%d, len=%d, buf=%s, return(written)=%d, url=%s\n", this, npp, mPosition, numtowrite, (char *)mStreamBuffer, writeCount, mNPStream.url));  if (writeCount < 0) { rv = NS_ERROR_FAILURE; goto error; }  if (sourceOffset == 0) mPosition += numtowrite;  amountRead -= numtowrite; } }  rv = NS_OK;  error: if (PR_TRUE == createdHere) { PR_Free(mStreamBuffer); mStreamBuffer=nsnull; }  if (leftToRead > 0) { OnDataAvailable(pluginInfo, input, sourceOffset, leftToRead); }  return rv;
ns4xPluginStreamListener::OnDataAvailable(nsIPluginStreamInfo* pluginInfo,										  nsIInputStream* input,                                          PRUint32 length){	const NPPluginFuncs *callbacks;    NPP                 npp;	PRUint32			numtowrite = 0;	PRUint32			amountRead = 0;	PRInt32				writeCount = 0;    pluginInfo->GetURL(&mNPStream.url);    pluginInfo->GetLastModified((PRUint32*)&(mNPStream.lastmodified));    mInst->GetCallbacks(&callbacks);    mInst->GetNPP(&npp);    if (callbacks->write == NULL || length == 0)        return NS_OK; // XXX ?	// Get the data from the input stream	char* buffer = (char*) PR_Malloc(length);    if (buffer)         input->Read(buffer, length, &amountRead);	// amountRead tells us how many bytes were put in the buffer	// WriteReady returns to us how many bytes the plugin is 	// ready to handle  - we have to keep calling WriteReady and	// Write until the buffer is empty    while (amountRead > 0)    {		if (callbacks->writeready != NULL)		{#if !TARGET_CARBON// pinkerton// relies on routine descriptors, not present in carbon. We need to fix this.		numtowrite = CallNPP_WriteReadyProc(callbacks->writeready,                                            npp,                                            &mNPStream);#endif				if (numtowrite > amountRead)			numtowrite = amountRead;		}		else // if WriteReady is not supported by the plugin, just write the whole buffer			numtowrite = length;		// if WriteReady returned 0, the plugin is not ready to handle the data,		// so just skip the Write until WriteReady returns a >0 value		if(numtowrite > 0)		{#if !TARGET_CARBON// pinkerton// relies on routine descriptors, not present in carbon. We need to fix this.			writeCount = CallNPP_WriteProc(callbacks->write,                                       npp,                                       &mNPStream,                                        mPosition,                                       numtowrite,                                       (void *)buffer);			if(writeCount < 0)				return NS_ERROR_FAILURE;#endif			amountRead -= numtowrite;			mPosition += numtowrite;		}    }    return NS_OK;}