1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/modules/libjar/zipwriter/src/StreamFunctions.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,68 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.7 + */ 1.8 + 1.9 +#ifndef _nsStreamFunctions_h_ 1.10 +#define _nsStreamFunctions_h_ 1.11 + 1.12 +#include "nscore.h" 1.13 +#include "nsIInputStream.h" 1.14 +#include "nsIOutputStream.h" 1.15 + 1.16 +/* 1.17 + * ZIP file data is stored little-endian. These are helper functions to read and 1.18 + * write little endian data to/from a char buffer. 1.19 + * The off argument, where present, is incremented according to the number of 1.20 + * bytes consumed from the buffer. 1.21 + */ 1.22 +inline NS_HIDDEN_(void) WRITE8(uint8_t* buf, uint32_t* off, uint8_t val) 1.23 +{ 1.24 + buf[(*off)++] = val; 1.25 +} 1.26 + 1.27 +inline NS_HIDDEN_(void) WRITE16(uint8_t* buf, uint32_t* off, uint16_t val) 1.28 +{ 1.29 + WRITE8(buf, off, val & 0xff); 1.30 + WRITE8(buf, off, (val >> 8) & 0xff); 1.31 +} 1.32 + 1.33 +inline NS_HIDDEN_(void) WRITE32(uint8_t* buf, uint32_t* off, uint32_t val) 1.34 +{ 1.35 + WRITE16(buf, off, val & 0xffff); 1.36 + WRITE16(buf, off, (val >> 16) & 0xffff); 1.37 +} 1.38 + 1.39 +inline NS_HIDDEN_(uint8_t) READ8(const uint8_t* buf, uint32_t* off) 1.40 +{ 1.41 + return buf[(*off)++]; 1.42 +} 1.43 + 1.44 +inline NS_HIDDEN_(uint16_t) READ16(const uint8_t* buf, uint32_t* off) 1.45 +{ 1.46 + uint16_t val = READ8(buf, off); 1.47 + val |= READ8(buf, off) << 8; 1.48 + return val; 1.49 +} 1.50 + 1.51 +inline NS_HIDDEN_(uint32_t) READ32(const uint8_t* buf, uint32_t* off) 1.52 +{ 1.53 + uint32_t val = READ16(buf, off); 1.54 + val |= READ16(buf, off) << 16; 1.55 + return val; 1.56 +} 1.57 + 1.58 +inline NS_HIDDEN_(uint32_t) PEEK32(const uint8_t* buf) 1.59 +{ 1.60 + return (uint32_t)( (buf [0] ) | 1.61 + (buf [1] << 8) | 1.62 + (buf [2] << 16) | 1.63 + (buf [3] << 24) ); 1.64 +} 1.65 + 1.66 +NS_HIDDEN_(nsresult) ZW_ReadData(nsIInputStream *aStream, char *aBuffer, uint32_t aCount); 1.67 + 1.68 +NS_HIDDEN_(nsresult) ZW_WriteData(nsIOutputStream *aStream, const char *aBuffer, 1.69 + uint32_t aCount); 1.70 + 1.71 +#endif