forked from Floorp-Projects/Floorp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileStream.h
140 lines (110 loc) · 2.93 KB
/
FileStream.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_indexeddb_filestream_h__
#define mozilla_dom_indexeddb_filestream_h__
#include "IndexedDatabase.h"
#include "nsIFileStreams.h"
#include "nsIInputStream.h"
#include "nsIOutputStream.h"
#include "nsISeekableStream.h"
#include "nsIStandardFileStream.h"
class nsIFile;
struct quota_FILE;
BEGIN_INDEXEDDB_NAMESPACE
class FileStream : public nsISeekableStream,
public nsIInputStream,
public nsIOutputStream,
public nsIStandardFileStream,
public nsIFileMetadata
{
public:
FileStream()
: mFlags(0),
mDeferredOpen(false),
mQuotaFile(nullptr)
{ }
virtual ~FileStream()
{
Close();
}
NS_DECL_ISUPPORTS
NS_DECL_NSISEEKABLESTREAM
NS_DECL_NSISTANDARDFILESTREAM
NS_DECL_NSIFILEMETADATA
// nsIInputStream
NS_IMETHOD
Close();
NS_IMETHOD
Available(uint64_t* _retval);
NS_IMETHOD
Read(char* aBuf, uint32_t aCount, uint32_t* _retval);
NS_IMETHOD
ReadSegments(nsWriteSegmentFun aWriter, void* aClosure, uint32_t aCount,
uint32_t* _retval);
NS_IMETHOD
IsNonBlocking(bool* _retval);
// nsIOutputStream
// Close() already declared
NS_IMETHOD
Flush();
NS_IMETHOD
Write(const char* aBuf, uint32_t aCount, uint32_t* _retval);
NS_IMETHOD
WriteFrom(nsIInputStream* aFromStream, uint32_t aCount, uint32_t* _retval);
NS_IMETHOD
WriteSegments(nsReadSegmentFun aReader, void* aClosure, uint32_t aCount,
uint32_t* _retval);
// IsNonBlocking() already declared
protected:
/**
* Cleans up data prepared in Init.
*/
void
CleanUpOpen()
{
mFilePath.Truncate();
mDeferredOpen = false;
}
/**
* Open the file. This is called either from Init
* or from DoPendingOpen (if FLAGS_DEFER_OPEN is used when initializing this
* stream). The default behavior of DoOpen is to open the file and save the
* file descriptor.
*/
virtual nsresult
DoOpen();
/**
* If there is a pending open, do it now. It's important for this to be
* inlined since we do it in almost every stream API call.
*/
nsresult
DoPendingOpen()
{
if (!mDeferredOpen) {
return NS_OK;
}
return DoOpen();
}
/**
* Data we need to do an open.
*/
nsString mFilePath;
nsString mMode;
/**
* Flags describing our behavior. See the IDL file for possible values.
*/
int32_t mFlags;
/**
* Whether we have a pending open (see FLAGS_DEFER_OPEN in the IDL file).
*/
bool mDeferredOpen;
/**
* File descriptor for opened file.
*/
quota_FILE* mQuotaFile;
};
END_INDEXEDDB_NAMESPACE
#endif // mozilla_dom_indexeddb_filestream_h__