michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: */ michael@0: michael@0: #ifndef _nsStreamFunctions_h_ michael@0: #define _nsStreamFunctions_h_ michael@0: michael@0: #include "nscore.h" michael@0: #include "nsIInputStream.h" michael@0: #include "nsIOutputStream.h" michael@0: michael@0: /* michael@0: * ZIP file data is stored little-endian. These are helper functions to read and michael@0: * write little endian data to/from a char buffer. michael@0: * The off argument, where present, is incremented according to the number of michael@0: * bytes consumed from the buffer. michael@0: */ michael@0: inline NS_HIDDEN_(void) WRITE8(uint8_t* buf, uint32_t* off, uint8_t val) michael@0: { michael@0: buf[(*off)++] = val; michael@0: } michael@0: michael@0: inline NS_HIDDEN_(void) WRITE16(uint8_t* buf, uint32_t* off, uint16_t val) michael@0: { michael@0: WRITE8(buf, off, val & 0xff); michael@0: WRITE8(buf, off, (val >> 8) & 0xff); michael@0: } michael@0: michael@0: inline NS_HIDDEN_(void) WRITE32(uint8_t* buf, uint32_t* off, uint32_t val) michael@0: { michael@0: WRITE16(buf, off, val & 0xffff); michael@0: WRITE16(buf, off, (val >> 16) & 0xffff); michael@0: } michael@0: michael@0: inline NS_HIDDEN_(uint8_t) READ8(const uint8_t* buf, uint32_t* off) michael@0: { michael@0: return buf[(*off)++]; michael@0: } michael@0: michael@0: inline NS_HIDDEN_(uint16_t) READ16(const uint8_t* buf, uint32_t* off) michael@0: { michael@0: uint16_t val = READ8(buf, off); michael@0: val |= READ8(buf, off) << 8; michael@0: return val; michael@0: } michael@0: michael@0: inline NS_HIDDEN_(uint32_t) READ32(const uint8_t* buf, uint32_t* off) michael@0: { michael@0: uint32_t val = READ16(buf, off); michael@0: val |= READ16(buf, off) << 16; michael@0: return val; michael@0: } michael@0: michael@0: inline NS_HIDDEN_(uint32_t) PEEK32(const uint8_t* buf) michael@0: { michael@0: return (uint32_t)( (buf [0] ) | michael@0: (buf [1] << 8) | michael@0: (buf [2] << 16) | michael@0: (buf [3] << 24) ); michael@0: } michael@0: michael@0: NS_HIDDEN_(nsresult) ZW_ReadData(nsIInputStream *aStream, char *aBuffer, uint32_t aCount); michael@0: michael@0: NS_HIDDEN_(nsresult) ZW_WriteData(nsIOutputStream *aStream, const char *aBuffer, michael@0: uint32_t aCount); michael@0: michael@0: #endif