2003-03-14 21:59:51 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
1999-10-26 23:43:26 +04:00
|
|
|
/* nsJARInputStream.cpp
|
|
|
|
*
|
2004-04-19 02:01:16 +04:00
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-10-26 23:43:26 +04:00
|
|
|
*
|
2004-04-19 02:01:16 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
2005-12-15 16:48:48 +03:00
|
|
|
* The Original Code is Netscape Communicator source code.
|
2004-04-19 02:01:16 +04:00
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1999
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Mitch Stoltz <mstoltz@netscape.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2003-03-14 21:59:51 +03:00
|
|
|
|
1999-10-26 23:43:26 +04:00
|
|
|
#include "nsJARInputStream.h"
|
|
|
|
#include "zipfile.h" // defines ZIP error codes
|
|
|
|
#include "nsZipArchive.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------
|
|
|
|
* nsISupports implementation
|
|
|
|
*--------------------------------------------*/
|
|
|
|
|
2003-09-08 02:56:05 +04:00
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS1(nsJARInputStream, nsIInputStream)
|
1999-10-26 23:43:26 +04:00
|
|
|
|
|
|
|
/*----------------------------------------------------------
|
|
|
|
* nsJARInputStream implementation
|
|
|
|
*--------------------------------------------------------*/
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJARInputStream::Available(PRUint32 *_retval)
|
|
|
|
{
|
2006-01-02 05:30:32 +03:00
|
|
|
if (!mJAR)
|
|
|
|
return NS_BASE_STREAM_CLOSED;
|
|
|
|
|
2003-03-14 21:59:51 +03:00
|
|
|
*_retval = mReadInfo.Available();
|
|
|
|
return NS_OK;
|
1999-10-26 23:43:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-02-14 04:57:01 +03:00
|
|
|
nsJARInputStream::Read(char* buf, PRUint32 count, PRUint32 *bytesRead)
|
1999-10-26 23:43:26 +04:00
|
|
|
{
|
2006-01-02 05:30:32 +03:00
|
|
|
if (!mJAR) {
|
|
|
|
*bytesRead = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2003-03-14 21:59:51 +03:00
|
|
|
|
|
|
|
PRInt32 err = mReadInfo.Read(buf, count, bytesRead);
|
|
|
|
return err == ZIP_OK ? NS_OK : NS_ERROR_FAILURE;
|
1999-10-26 23:43:26 +04:00
|
|
|
}
|
|
|
|
|
2000-08-22 11:03:33 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJARInputStream::ReadSegments(nsWriteSegmentFun writer, void * closure, PRUint32 count, PRUint32 *_retval)
|
|
|
|
{
|
2003-03-14 21:59:51 +03:00
|
|
|
// don't have a buffer to read from, so this better not be called!
|
|
|
|
NS_NOTREACHED("Consumers should be using Read()!");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2000-08-22 11:03:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-12 03:59:06 +03:00
|
|
|
nsJARInputStream::IsNonBlocking(PRBool *aNonBlocking)
|
2000-08-22 11:03:33 +04:00
|
|
|
{
|
2002-03-12 03:59:06 +03:00
|
|
|
*aNonBlocking = PR_FALSE;
|
|
|
|
return NS_OK;
|
2000-08-22 11:03:33 +04:00
|
|
|
}
|
|
|
|
|
1999-10-26 23:43:26 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJARInputStream::Close()
|
|
|
|
{
|
2006-03-30 02:10:37 +04:00
|
|
|
mJAR = nsnull;
|
2003-03-14 21:59:51 +03:00
|
|
|
return NS_OK;
|
1999-10-26 23:43:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2000-07-12 07:10:33 +04:00
|
|
|
nsJARInputStream::Init(nsJAR* aJAR, const char* aFilename)
|
1999-10-26 23:43:26 +04:00
|
|
|
{
|
2006-03-30 02:10:37 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aJAR);
|
|
|
|
NS_ENSURE_ARG_POINTER(aFilename);
|
|
|
|
|
2000-03-30 11:41:37 +04:00
|
|
|
mJAR = aJAR;
|
2000-01-29 03:03:57 +03:00
|
|
|
|
2006-03-30 02:10:37 +04:00
|
|
|
// Don't assert if !fd, because it's possible that aJAR comes
|
|
|
|
// from a cache and aJAR's file has been deled
|
2003-03-14 21:59:51 +03:00
|
|
|
PRFileDesc* fd = aJAR->OpenFile();
|
|
|
|
if (!fd)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2006-03-30 02:10:37 +04:00
|
|
|
|
|
|
|
// mReadInfo takes ownership of fd here
|
|
|
|
PRInt32 result = aJAR->mZip.ReadInit(aFilename, &mReadInfo, fd);
|
1999-10-26 23:43:26 +04:00
|
|
|
if (result != ZIP_OK)
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-02-14 04:57:01 +03:00
|
|
|
return NS_OK;
|
1999-10-26 23:43:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------
|
|
|
|
// nsJARInputStream constructor and destructor
|
|
|
|
//----------------------------------------------
|
|
|
|
|
2000-01-29 03:03:57 +03:00
|
|
|
nsJARInputStream::nsJARInputStream()
|
1999-10-26 23:43:26 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsJARInputStream::~nsJARInputStream()
|
|
|
|
{
|
2000-01-29 03:03:57 +03:00
|
|
|
Close();
|
1999-10-26 23:43:26 +04:00
|
|
|
}
|