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>
|
2009-08-13 00:50:12 +04:00
|
|
|
* Taras Glek <tglek@mozilla.com>
|
2004-04-19 02:01:16 +04:00
|
|
|
*
|
|
|
|
* 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"
|
2006-05-02 23:33:09 +04:00
|
|
|
#include "zipstruct.h" // defines ZIP compression codes
|
1999-10-26 23:43:26 +04:00
|
|
|
#include "nsZipArchive.h"
|
|
|
|
|
2006-10-10 17:24:57 +04:00
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsEscape.h"
|
|
|
|
#include "nsIFile.h"
|
2009-08-13 00:50:12 +04:00
|
|
|
#include "nsDebug.h"
|
2010-11-11 23:13:48 +03:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
1999-10-26 23:43:26 +04:00
|
|
|
|
|
|
|
/*---------------------------------------------
|
|
|
|
* 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
|
|
|
|
*--------------------------------------------------------*/
|
|
|
|
|
2006-05-02 23:33:09 +04:00
|
|
|
nsresult
|
2009-10-04 21:20:45 +04:00
|
|
|
nsJARInputStream::InitFile(nsJAR *aJar, nsZipItem *item)
|
2006-05-02 23:33:09 +04:00
|
|
|
{
|
2009-10-04 21:20:45 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
NS_ABORT_IF_FALSE(aJar, "Argument may not be null");
|
2009-08-13 00:50:12 +04:00
|
|
|
NS_ABORT_IF_FALSE(item, "Argument may not be null");
|
2006-05-02 23:33:09 +04:00
|
|
|
|
|
|
|
// Mark it as closed, in case something fails in initialisation
|
2009-10-04 21:20:45 +04:00
|
|
|
mMode = MODE_CLOSED;
|
2006-05-02 23:33:09 +04:00
|
|
|
//-- prepare for the compression type
|
2009-10-17 19:54:54 +04:00
|
|
|
switch (item->Compression()) {
|
2006-05-02 23:33:09 +04:00
|
|
|
case STORED:
|
2009-10-04 21:20:45 +04:00
|
|
|
mMode = MODE_COPY;
|
2006-05-02 23:33:09 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DEFLATED:
|
2009-10-04 21:20:45 +04:00
|
|
|
rv = gZlibInit(&mZs);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-05-02 23:33:09 +04:00
|
|
|
|
2009-10-04 21:20:45 +04:00
|
|
|
mMode = MODE_INFLATE;
|
2009-10-17 19:54:54 +04:00
|
|
|
mInCrc = item->CRC32();
|
2009-10-04 21:20:45 +04:00
|
|
|
mOutCrc = crc32(0L, Z_NULL, 0);
|
2006-05-02 23:33:09 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2009-10-04 21:20:45 +04:00
|
|
|
// Must keep handle to filepointer and mmap structure as long as we need access to the mmapped data
|
2010-09-10 01:01:00 +04:00
|
|
|
mFd = aJar->mZip->GetFD();
|
|
|
|
mZs.next_in = (Bytef *)aJar->mZip->GetData(item);
|
2009-12-31 21:10:20 +03:00
|
|
|
if (!mZs.next_in)
|
|
|
|
return NS_ERROR_FILE_CORRUPTED;
|
2009-10-17 19:54:54 +04:00
|
|
|
mZs.avail_in = item->Size();
|
|
|
|
mOutSize = item->RealSize();
|
2009-10-04 21:20:45 +04:00
|
|
|
mZs.total_out = 0;
|
2006-10-10 17:24:57 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2009-08-13 00:50:12 +04:00
|
|
|
nsJARInputStream::InitDirectory(nsJAR* aJar,
|
2006-10-10 17:24:57 +04:00
|
|
|
const nsACString& aJarDirSpec,
|
|
|
|
const char* aDir)
|
|
|
|
{
|
2009-08-13 00:50:12 +04:00
|
|
|
NS_ABORT_IF_FALSE(aJar, "Argument may not be null");
|
|
|
|
NS_ABORT_IF_FALSE(aDir, "Argument may not be null");
|
2006-10-10 17:24:57 +04:00
|
|
|
|
|
|
|
// Mark it as closed, in case something fails in initialisation
|
2009-10-04 21:20:45 +04:00
|
|
|
mMode = MODE_CLOSED;
|
2006-10-10 17:24:57 +04:00
|
|
|
|
|
|
|
// Keep the zipReader for getting the actual zipItems
|
2009-08-13 00:50:12 +04:00
|
|
|
mJar = aJar;
|
2006-10-10 17:24:57 +04:00
|
|
|
nsZipFind *find;
|
|
|
|
nsresult rv;
|
2007-01-22 04:47:50 +03:00
|
|
|
// We can get aDir's contents as strings via FindEntries
|
|
|
|
// with the following pattern (see nsIZipReader.findEntries docs)
|
|
|
|
// assuming dirName is properly escaped:
|
|
|
|
//
|
|
|
|
// dirName + "?*~" + dirName + "?*/?*"
|
|
|
|
nsDependentCString dirName(aDir);
|
|
|
|
mNameLen = dirName.Length();
|
|
|
|
|
|
|
|
// iterate through dirName and copy it to escDirName, escaping chars
|
|
|
|
// which are special at the "top" level of the regexp so FindEntries
|
|
|
|
// works correctly
|
|
|
|
nsCAutoString escDirName;
|
|
|
|
const char* curr = dirName.BeginReading();
|
|
|
|
const char* end = dirName.EndReading();
|
|
|
|
while (curr != end) {
|
|
|
|
switch (*curr) {
|
|
|
|
case '*':
|
|
|
|
case '?':
|
|
|
|
case '$':
|
|
|
|
case '[':
|
|
|
|
case ']':
|
|
|
|
case '^':
|
|
|
|
case '~':
|
|
|
|
case '(':
|
|
|
|
case ')':
|
|
|
|
case '\\':
|
|
|
|
escDirName.Append('\\');
|
|
|
|
// fall through
|
|
|
|
default:
|
|
|
|
escDirName.Append(*curr);
|
2006-10-10 17:24:57 +04:00
|
|
|
}
|
2007-01-22 04:47:50 +03:00
|
|
|
++curr;
|
2006-10-10 17:24:57 +04:00
|
|
|
}
|
2007-01-22 04:47:50 +03:00
|
|
|
nsCAutoString pattern = escDirName + NS_LITERAL_CSTRING("?*~") +
|
|
|
|
escDirName + NS_LITERAL_CSTRING("?*/?*");
|
2010-09-10 01:01:00 +04:00
|
|
|
rv = mJar->mZip->FindInit(pattern.get(), &find);
|
2006-10-10 17:24:57 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
const char *name;
|
2009-10-17 19:54:54 +04:00
|
|
|
PRUint16 nameLen;
|
|
|
|
while ((rv = find->FindNext( &name, &nameLen )) == NS_OK) {
|
|
|
|
// Must copy, to make it zero-terminated
|
|
|
|
mArray.AppendElement(nsCString(name,nameLen));
|
2006-10-10 17:24:57 +04:00
|
|
|
}
|
|
|
|
delete find;
|
|
|
|
|
|
|
|
if (rv != NS_ERROR_FILE_TARGET_DOES_NOT_EXIST && NS_FAILED(rv)) {
|
|
|
|
return NS_ERROR_FAILURE; // no error translation
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort it
|
|
|
|
mArray.Sort();
|
|
|
|
|
|
|
|
mBuffer.AssignLiteral("300: ");
|
|
|
|
mBuffer.Append(aJarDirSpec);
|
|
|
|
mBuffer.AppendLiteral("\n200: filename content-length last-modified file-type\n");
|
|
|
|
|
|
|
|
// Open for reading
|
2009-10-04 21:20:45 +04:00
|
|
|
mMode = MODE_DIRECTORY;
|
|
|
|
mZs.total_out = 0;
|
2006-10-10 17:24:57 +04:00
|
|
|
mArrPos = 0;
|
2006-05-02 23:33:09 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-10-26 23:43:26 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJARInputStream::Available(PRUint32 *_retval)
|
|
|
|
{
|
2009-10-04 21:20:45 +04:00
|
|
|
// A lot of callers don't check the error code.
|
|
|
|
// They just use the _retval value.
|
|
|
|
*_retval = 0;
|
|
|
|
|
|
|
|
switch (mMode) {
|
|
|
|
case MODE_NOTINITED:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MODE_CLOSED:
|
2006-01-02 05:30:32 +03:00
|
|
|
return NS_BASE_STREAM_CLOSED;
|
|
|
|
|
2009-10-04 21:20:45 +04:00
|
|
|
case MODE_DIRECTORY:
|
2006-10-10 17:24:57 +04:00
|
|
|
*_retval = mBuffer.Length();
|
2009-10-04 21:20:45 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MODE_INFLATE:
|
|
|
|
case MODE_COPY:
|
|
|
|
*_retval = mOutSize - mZs.total_out;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-03-14 21:59:51 +03:00
|
|
|
return NS_OK;
|
1999-10-26 23:43:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2006-05-02 23:33:09 +04:00
|
|
|
nsJARInputStream::Read(char* aBuffer, PRUint32 aCount, PRUint32 *aBytesRead)
|
1999-10-26 23:43:26 +04:00
|
|
|
{
|
2006-05-02 23:33:09 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aBuffer);
|
|
|
|
NS_ENSURE_ARG_POINTER(aBytesRead);
|
|
|
|
|
|
|
|
*aBytesRead = 0;
|
|
|
|
|
2009-09-03 16:15:19 +04:00
|
|
|
nsresult rv = NS_OK;
|
2010-11-11 23:13:48 +03:00
|
|
|
MOZ_WIN_MEM_TRY_BEGIN
|
2009-10-04 21:20:45 +04:00
|
|
|
switch (mMode) {
|
|
|
|
case MODE_NOTINITED:
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
case MODE_CLOSED:
|
|
|
|
return NS_BASE_STREAM_CLOSED;
|
|
|
|
|
|
|
|
case MODE_DIRECTORY:
|
|
|
|
return ReadDirectory(aBuffer, aCount, aBytesRead);
|
|
|
|
|
|
|
|
case MODE_INFLATE:
|
|
|
|
if (mFd) {
|
|
|
|
rv = ContinueInflate(aBuffer, aCount, aBytesRead);
|
2009-09-03 16:15:19 +04:00
|
|
|
}
|
2009-10-04 21:20:45 +04:00
|
|
|
// be aggressive about releasing the file!
|
|
|
|
// note that sometimes, we will release mFd before we've finished
|
2006-10-10 17:24:57 +04:00
|
|
|
// deflating - this is because zlib buffers the input
|
2009-10-04 21:20:45 +04:00
|
|
|
if (mZs.avail_in == 0) {
|
|
|
|
mFd = nsnull;
|
2006-05-02 23:33:09 +04:00
|
|
|
}
|
2009-10-04 21:20:45 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MODE_COPY:
|
|
|
|
if (mFd) {
|
2009-12-13 20:32:10 +03:00
|
|
|
PRUint32 count = NS_MIN(aCount, mOutSize - PRUint32(mZs.total_out));
|
2009-10-04 21:20:45 +04:00
|
|
|
if (count) {
|
|
|
|
memcpy(aBuffer, mZs.next_in + mZs.total_out, count);
|
|
|
|
mZs.total_out += count;
|
|
|
|
}
|
|
|
|
*aBytesRead = count;
|
|
|
|
}
|
|
|
|
// be aggressive about releasing the file!
|
|
|
|
// note that sometimes, we will release mFd before we've finished copying.
|
|
|
|
if (mZs.total_out >= mOutSize) {
|
|
|
|
mFd = nsnull;
|
|
|
|
}
|
|
|
|
break;
|
2006-05-02 23:33:09 +04:00
|
|
|
}
|
2010-11-11 23:13:48 +03:00
|
|
|
MOZ_WIN_MEM_TRY_CATCH(rv = NS_ERROR_FAILURE)
|
2009-09-03 16:15:19 +04:00
|
|
|
return rv;
|
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()
|
|
|
|
{
|
2009-10-04 21:20:45 +04:00
|
|
|
mMode = MODE_CLOSED;
|
|
|
|
mFd = nsnull;
|
2003-03-14 21:59:51 +03:00
|
|
|
return NS_OK;
|
1999-10-26 23:43:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2006-05-02 23:33:09 +04:00
|
|
|
nsJARInputStream::ContinueInflate(char* aBuffer, PRUint32 aCount,
|
|
|
|
PRUint32* aBytesRead)
|
1999-10-26 23:43:26 +04:00
|
|
|
{
|
2006-05-02 23:33:09 +04:00
|
|
|
// No need to check the args, ::Read did that, but assert them at least
|
|
|
|
NS_ASSERTION(aBuffer,"aBuffer parameter must not be null");
|
|
|
|
NS_ASSERTION(aBytesRead,"aBytesRead parameter must not be null");
|
1999-10-26 23:43:26 +04:00
|
|
|
|
2006-05-02 23:33:09 +04:00
|
|
|
// Keep old total_out count
|
2009-10-04 21:20:45 +04:00
|
|
|
const PRUint32 oldTotalOut = mZs.total_out;
|
2006-05-02 23:33:09 +04:00
|
|
|
|
|
|
|
// make sure we aren't reading too much
|
2009-12-13 20:32:10 +03:00
|
|
|
mZs.avail_out = NS_MIN(aCount, (mOutSize-oldTotalOut));
|
2009-10-04 21:20:45 +04:00
|
|
|
mZs.next_out = (unsigned char*)aBuffer;
|
1999-10-26 23:43:26 +04:00
|
|
|
|
2009-10-04 21:20:45 +04:00
|
|
|
// now inflate
|
|
|
|
int zerr = inflate(&mZs, Z_SYNC_FLUSH);
|
2006-05-02 23:33:09 +04:00
|
|
|
if ((zerr != Z_OK) && (zerr != Z_STREAM_END))
|
|
|
|
return NS_ERROR_FILE_CORRUPTED;
|
1999-10-26 23:43:26 +04:00
|
|
|
|
2009-10-04 21:20:45 +04:00
|
|
|
*aBytesRead = (mZs.total_out - oldTotalOut);
|
2006-05-02 23:33:09 +04:00
|
|
|
|
|
|
|
// Calculate the CRC on the output
|
2009-10-04 21:20:45 +04:00
|
|
|
mOutCrc = crc32(mOutCrc, (unsigned char*)aBuffer, *aBytesRead);
|
2006-05-02 23:33:09 +04:00
|
|
|
|
|
|
|
// be aggressive about ending the inflation
|
|
|
|
// for some reason we don't always get Z_STREAM_END
|
2009-10-04 21:20:45 +04:00
|
|
|
if (zerr == Z_STREAM_END || mZs.total_out == mOutSize) {
|
|
|
|
inflateEnd(&mZs);
|
2006-05-02 23:33:09 +04:00
|
|
|
|
|
|
|
// stop returning valid data as soon as we know we have a bad CRC
|
2009-10-04 21:20:45 +04:00
|
|
|
if (mOutCrc != mInCrc) {
|
2006-05-02 23:33:09 +04:00
|
|
|
// asserting because while this rarely happens, you definitely
|
|
|
|
// want to catch it in debug builds!
|
|
|
|
NS_NOTREACHED(0);
|
|
|
|
return NS_ERROR_FILE_CORRUPTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
1999-10-26 23:43:26 +04:00
|
|
|
}
|
2006-10-10 17:24:57 +04:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsJARInputStream::ReadDirectory(char* aBuffer, PRUint32 aCount, PRUint32 *aBytesRead)
|
|
|
|
{
|
|
|
|
// No need to check the args, ::Read did that, but assert them at least
|
|
|
|
NS_ASSERTION(aBuffer,"aBuffer parameter must not be null");
|
|
|
|
NS_ASSERTION(aBytesRead,"aBytesRead parameter must not be null");
|
|
|
|
|
|
|
|
// If the buffer contains data, copy what's there up to the desired amount
|
|
|
|
PRUint32 numRead = CopyDataToBuffer(aBuffer, aCount);
|
|
|
|
|
|
|
|
if (aCount > 0) {
|
|
|
|
// empty the buffer and start writing directory entry lines to it
|
|
|
|
mBuffer.Truncate();
|
|
|
|
mCurPos = 0;
|
2009-01-22 07:15:34 +03:00
|
|
|
const PRUint32 arrayLen = mArray.Length();
|
2006-10-10 17:24:57 +04:00
|
|
|
|
|
|
|
for ( ;aCount > mBuffer.Length(); mArrPos++) {
|
|
|
|
// have we consumed all the directory contents?
|
|
|
|
if (arrayLen <= mArrPos)
|
|
|
|
break;
|
|
|
|
|
2009-01-22 07:15:34 +03:00
|
|
|
const char * entryName = mArray[mArrPos].get();
|
|
|
|
PRUint32 entryNameLen = mArray[mArrPos].Length();
|
2010-09-10 01:01:00 +04:00
|
|
|
nsZipItem* ze = mJar->mZip->GetItem(entryName);
|
2006-10-10 17:24:57 +04:00
|
|
|
NS_ENSURE_TRUE(ze, NS_ERROR_FILE_TARGET_DOES_NOT_EXIST);
|
|
|
|
|
|
|
|
// Last Modified Time
|
|
|
|
PRExplodedTime tm;
|
2009-12-16 02:01:08 +03:00
|
|
|
PR_ExplodeTime(ze->LastModTime(), PR_GMTParameters, &tm);
|
2006-10-10 17:24:57 +04:00
|
|
|
char itemLastModTime[65];
|
|
|
|
PR_FormatTimeUSEnglish(itemLastModTime,
|
|
|
|
sizeof(itemLastModTime),
|
|
|
|
" %a,%%20%d%%20%b%%20%Y%%20%H:%M:%S%%20GMT ",
|
|
|
|
&tm);
|
|
|
|
|
|
|
|
// write a 201: line to the buffer for this item
|
|
|
|
// 200: filename content-length last-modified file-type
|
|
|
|
mBuffer.AppendLiteral("201: ");
|
|
|
|
|
|
|
|
// Names must be escaped and relative, so use the pre-calculated length
|
|
|
|
// of the directory name as the offset into the string
|
|
|
|
// NS_EscapeURL adds the escaped URL to the give string buffer
|
|
|
|
NS_EscapeURL(entryName + mNameLen,
|
|
|
|
entryNameLen - mNameLen,
|
|
|
|
esc_Minimal | esc_AlwaysCopy,
|
|
|
|
mBuffer);
|
|
|
|
|
|
|
|
mBuffer.Append(' ');
|
2009-10-17 19:54:54 +04:00
|
|
|
mBuffer.AppendInt(ze->RealSize(), 10);
|
2006-10-10 17:24:57 +04:00
|
|
|
mBuffer.Append(itemLastModTime); // starts/ends with ' '
|
2009-10-17 19:54:54 +04:00
|
|
|
if (ze->IsDirectory())
|
2006-10-10 17:24:57 +04:00
|
|
|
mBuffer.AppendLiteral("DIRECTORY\n");
|
|
|
|
else
|
|
|
|
mBuffer.AppendLiteral("FILE\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy up to the desired amount of data to buffer
|
|
|
|
numRead += CopyDataToBuffer(aBuffer, aCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
*aBytesRead = numRead;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32
|
|
|
|
nsJARInputStream::CopyDataToBuffer(char* &aBuffer, PRUint32 &aCount)
|
|
|
|
{
|
2009-12-13 20:32:10 +03:00
|
|
|
const PRUint32 writeLength = NS_MIN(aCount, mBuffer.Length() - mCurPos);
|
2006-10-10 17:24:57 +04:00
|
|
|
|
|
|
|
if (writeLength > 0) {
|
|
|
|
memcpy(aBuffer, mBuffer.get() + mCurPos, writeLength);
|
|
|
|
mCurPos += writeLength;
|
|
|
|
aCount -= writeLength;
|
|
|
|
aBuffer += writeLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
// return number of bytes copied to the buffer so the
|
|
|
|
// Read method can return the number of bytes copied
|
|
|
|
return writeLength;
|
|
|
|
}
|