Line data Source code
1 : /* This Source Code Form is subject to the terms of the Mozilla Public
2 : * License, v. 2.0. If a copy of the MPL was not distributed with this
3 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 : */
5 :
6 : #ifndef _nsZipWriter_h_
7 : #define _nsZipWriter_h_
8 :
9 : #include "nsIZipWriter.h"
10 : #include "nsIFileStreams.h"
11 : #include "nsIBufferedStreams.h"
12 : #include "nsIRequestObserver.h"
13 : #include "nsZipHeader.h"
14 : #include "nsCOMPtr.h"
15 : #include "nsCOMArray.h"
16 : #include "nsTArray.h"
17 : #include "nsDataHashtable.h"
18 : #include "mozilla/Attributes.h"
19 :
20 : #define ZIPWRITER_CONTRACTID "@mozilla.org/zipwriter;1"
21 : #define ZIPWRITER_CID { 0x430d416c, 0xa722, 0x4ad1, \
22 : { 0xbe, 0x98, 0xd9, 0xa4, 0x45, 0xf8, 0x5e, 0x3f } }
23 :
24 : #define OPERATION_ADD 0
25 : #define OPERATION_REMOVE 1
26 0 : struct nsZipQueueItem
27 : {
28 : public:
29 : uint32_t mOperation;
30 : nsCString mZipEntry;
31 : nsCOMPtr<nsIFile> mFile;
32 : nsCOMPtr<nsIChannel> mChannel;
33 : nsCOMPtr<nsIInputStream> mStream;
34 : PRTime mModTime;
35 : int32_t mCompression;
36 : uint32_t mPermissions;
37 : };
38 :
39 : class nsZipWriter final : public nsIZipWriter,
40 : public nsIRequestObserver
41 : {
42 : public:
43 : NS_DECL_ISUPPORTS
44 : NS_DECL_NSIZIPWRITER
45 : NS_DECL_NSIREQUESTOBSERVER
46 :
47 : nsZipWriter();
48 : nsresult EntryCompleteCallback(nsZipHeader *aHeader, nsresult aStatus);
49 :
50 : private:
51 : ~nsZipWriter();
52 :
53 : uint32_t mCDSOffset;
54 : bool mCDSDirty;
55 : bool mInQueue;
56 :
57 : nsCOMPtr<nsIFile> mFile;
58 : nsCOMPtr<nsIRequestObserver> mProcessObserver;
59 : nsCOMPtr<nsISupports> mProcessContext;
60 : nsCOMPtr<nsIOutputStream> mStream;
61 : nsCOMArray<nsZipHeader> mHeaders;
62 : nsTArray<nsZipQueueItem> mQueue;
63 : nsDataHashtable<nsCStringHashKey, int32_t> mEntryHash;
64 : nsCString mComment;
65 :
66 : nsresult SeekCDS();
67 : void Cleanup();
68 : nsresult ReadFile(nsIFile *aFile);
69 : nsresult InternalAddEntryDirectory(const nsACString & aZipEntry,
70 : PRTime aModTime, uint32_t aPermissions);
71 : nsresult BeginProcessingAddition(nsZipQueueItem* aItem, bool* complete);
72 : nsresult BeginProcessingRemoval(int32_t aPos);
73 : nsresult AddEntryStream(const nsACString & aZipEntry, PRTime aModTime,
74 : int32_t aCompression, nsIInputStream *aStream,
75 : bool aQueue, uint32_t aPermissions);
76 : void BeginProcessingNextItem();
77 : void FinishQueue(nsresult aStatus);
78 : };
79 :
80 : #endif
|