1 : /* ***** BEGIN LICENSE BLOCK *****
2 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 : *
4 : * The contents of this file are subject to the Mozilla Public License Version
5 : * 1.1 (the "License"); you may not use this file except in compliance with
6 : * the License. You may obtain a copy of the License at
7 : * http://www.mozilla.org/MPL/
8 : *
9 : * Software distributed under the License is distributed on an "AS IS" basis,
10 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 : * for the specific language governing rights and limitations under the
12 : * License.
13 : *
14 : * The Original Code is Zip Writer Component.
15 : *
16 : * The Initial Developer of the Original Code is
17 : * Dave Townsend <dtownsend@oxymoronical.com>.
18 : *
19 : * Portions created by the Initial Developer are Copyright (C) 2007
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Mook <mook.moz+random.code@gmail.com>
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either the GNU General Public License Version 2 or later (the "GPL"), or
27 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK *****
38 : */
39 :
40 : #ifndef _nsStreamFunctions_h_
41 : #define _nsStreamFunctions_h_
42 :
43 : #include "nscore.h"
44 : #include "nsIInputStream.h"
45 : #include "nsIOutputStream.h"
46 :
47 : /*
48 : * ZIP file data is stored little-endian. These are helper functions to read and
49 : * write little endian data to/from a char buffer.
50 : * The off argument, where present, is incremented according to the number of
51 : * bytes consumed from the buffer.
52 : */
53 680088 : inline NS_HIDDEN_(void) WRITE8(PRUint8* buf, PRUint32* off, PRUint8 val)
54 : {
55 680088 : buf[(*off)++] = val;
56 680088 : }
57 :
58 337176 : inline NS_HIDDEN_(void) WRITE16(PRUint8* buf, PRUint32* off, PRUint16 val)
59 : {
60 337176 : WRITE8(buf, off, val & 0xff);
61 337176 : WRITE8(buf, off, (val >> 8) & 0xff);
62 337176 : }
63 :
64 88829 : inline NS_HIDDEN_(void) WRITE32(PRUint8* buf, PRUint32* off, PRUint32 val)
65 : {
66 88829 : WRITE16(buf, off, val & 0xffff);
67 88829 : WRITE16(buf, off, (val >> 16) & 0xffff);
68 88829 : }
69 :
70 533 : inline NS_HIDDEN_(PRUint8) READ8(const PRUint8* buf, PRUint32* off)
71 : {
72 533 : return buf[(*off)++];
73 : }
74 :
75 263 : inline NS_HIDDEN_(PRUint16) READ16(const PRUint8* buf, PRUint32* off)
76 : {
77 263 : PRUint16 val = READ8(buf, off);
78 263 : val |= READ8(buf, off) << 8;
79 263 : return val;
80 : }
81 :
82 68 : inline NS_HIDDEN_(PRUint32) READ32(const PRUint8* buf, PRUint32* off)
83 : {
84 68 : PRUint32 val = READ16(buf, off);
85 68 : val |= READ16(buf, off) << 16;
86 68 : return val;
87 : }
88 :
89 3414 : inline NS_HIDDEN_(PRUint32) PEEK32(const PRUint8* buf)
90 : {
91 3414 : return (PRUint32)( (buf [0] ) |
92 3414 : (buf [1] << 8) |
93 3414 : (buf [2] << 16) |
94 10242 : (buf [3] << 24) );
95 : }
96 :
97 : NS_HIDDEN_(nsresult) ZW_ReadData(nsIInputStream *aStream, char *aBuffer, PRUint32 aCount);
98 :
99 : NS_HIDDEN_(nsresult) ZW_WriteData(nsIOutputStream *aStream, const char *aBuffer,
100 : PRUint32 aCount);
101 :
102 : #endif
|