Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qrandomaccessasyncfile.cpp
Go to the documentation of this file.
1
// Copyright (C) 2025 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#
include
"qrandomaccessasyncfile_p.h"
6
#
include
"qrandomaccessasyncfile_p_p.h"
7
8
QT_BEGIN_NAMESPACE
9
10
QRandomAccessAsyncFile::QRandomAccessAsyncFile(QObject *parent)
11
: QObject{*
new
QRandomAccessAsyncFilePrivate, parent}
12
{
13
d_func()->init();
14
}
15
16
QRandomAccessAsyncFile::~QRandomAccessAsyncFile()
17
{
18
close();
19
}
20
21
void
QRandomAccessAsyncFile::close()
22
{
23
Q_D(QRandomAccessAsyncFile);
24
d->close();
25
}
26
27
qint64 QRandomAccessAsyncFile::size()
const
28
{
29
Q_D(
const
QRandomAccessAsyncFile);
30
return
d->size();
31
}
32
33
/*!
34
\internal
35
36
Attempts to open the file \a filePath with mode \a mode.
37
38
\include qrandomaccessasyncfile.cpp returns-qiooperation
39
*/
40
QIOOperation *QRandomAccessAsyncFile::open(
const
QString &filePath, QIODeviceBase::OpenMode mode)
41
{
42
Q_D(QRandomAccessAsyncFile);
43
return
d->open(filePath, mode);
44
}
45
46
/*!
47
\internal
48
49
Flushes any buffered data to the file.
50
51
\include qrandomaccessasyncfile.cpp returns-qiooperation
52
*/
53
QIOOperation *QRandomAccessAsyncFile::flush()
54
{
55
Q_D(QRandomAccessAsyncFile);
56
return
d->flush();
57
}
58
59
/*!
60
\internal
61
62
Reads at maximum \a maxSize bytes, starting from \a offset.
63
64
The data is written to the internal buffer managed by the returned
65
QIOOperation object.
66
67
//! [returns-qiooperation]
68
Returns a QIOOperation object that would emit a QIOOperation::finished()
69
signal once the operation is complete.
70
//! [returns-qiooperation]
71
*/
72
QIOReadOperation *QRandomAccessAsyncFile::read(qint64 offset, qint64 maxSize)
73
{
74
Q_D(QRandomAccessAsyncFile);
75
if
(maxSize < 0) {
76
qWarning(
"Using a negative maxSize in QRandomAccessAsyncFile::read() is incorrect. "
77
"Resetting to zero!"
);
78
maxSize = 0;
79
}
80
return
d->read(offset, maxSize);
81
}
82
83
/*!
84
\internal
85
\overload
86
87
Reads the data from the file, starting from \a offset, and stores it into
88
\a buffer.
89
90
The amount of bytes to be read from the file is determined by the size of
91
the buffer. Note that the actual amount of read bytes can be less than that.
92
93
This operation does not take ownership of the provided buffer, so it is the
94
user's responsibility to make sure that the buffer is valid until the
95
returned QIOOperation completes.
96
97
\note The buffer might be populated from different threads, so the user
98
application should not access it until the returned QIOOperation completes.
99
100
\include qrandomaccessasyncfile.cpp returns-qiooperation
101
*/
102
QIOVectoredReadOperation *
103
QRandomAccessAsyncFile::readInto(qint64 offset, QSpan<std::byte> buffer)
104
{
105
Q_D(QRandomAccessAsyncFile);
106
return
d->readInto(offset, buffer);
107
}
108
109
/*!
110
\internal
111
112
Reads the data from the file, starting from \a offset, and stores it into
113
\a buffers.
114
115
The amount of bytes to be read from the file is determined by the sum of
116
sizes of all buffers. Note that the actual amount of read bytes can be less
117
than that.
118
119
This operation does not take ownership of the provided buffers, so it is the
120
user's responsibility to make sure that the buffers are valid until the
121
returned QIOOperation completes.
122
123
\note The buffers might be populated from different threads, so the user
124
application should not access them until the returned QIOOperation completes.
125
126
\include qrandomaccessasyncfile.cpp returns-qiooperation
127
*/
128
QIOVectoredReadOperation *
129
QRandomAccessAsyncFile::readInto(qint64 offset, QSpan<
const
QSpan<std::byte>> buffers)
130
{
131
Q_D(QRandomAccessAsyncFile);
132
return
d->readInto(offset, buffers);
133
}
134
135
/*!
136
\internal
137
138
Writes \a data into the file, starting from \a offset.
139
140
The \a data array is copied into the returned QIOOperation object.
141
142
\include qrandomaccessasyncfile.cpp returns-qiooperation
143
*/
144
QIOWriteOperation *QRandomAccessAsyncFile::write(qint64 offset,
const
QByteArray &data)
145
{
146
Q_D(QRandomAccessAsyncFile);
147
return
d->write(offset, data);
148
}
149
150
/*!
151
\internal
152
\overload
153
154
Writes \a data into the file, starting from \a offset.
155
156
The \a data array is moved into the returned QIOOperation object.
157
158
\include qrandomaccessasyncfile.cpp returns-qiooperation
159
*/
160
QIOWriteOperation *QRandomAccessAsyncFile::write(qint64 offset, QByteArray &&data)
161
{
162
Q_D(QRandomAccessAsyncFile);
163
return
d->write(offset, std::move(data));
164
}
165
166
/*!
167
\internal
168
\overload
169
170
Writes the content of \a buffer into the file, starting from \a offset.
171
172
This operation does not take ownership of the provided buffer, so it is the
173
user's responsibility to make sure that the buffer is valid until the
174
returned QIOOperation completes.
175
176
\note The buffer might be accessed from different threads, so the user
177
application should not modify it until the returned QIOOperation completes.
178
*/
179
QIOVectoredWriteOperation *
180
QRandomAccessAsyncFile::writeFrom(qint64 offset, QSpan<
const
std::byte> buffer)
181
{
182
Q_D(QRandomAccessAsyncFile);
183
return
d->writeFrom(offset, buffer);
184
}
185
186
/*!
187
\internal
188
189
Writes the content of \a buffers into the file, starting from \a offset.
190
191
This operation does not take ownership of the provided buffers, so it is the
192
user's responsibility to make sure that the buffers are valid until the
193
returned QIOOperation completes.
194
195
\note The buffers might be accessed from different threads, so the user
196
application should not modify them until the returned QIOOperation
197
completes.
198
*/
199
QIOVectoredWriteOperation *
200
QRandomAccessAsyncFile::writeFrom(qint64 offset, QSpan<
const
QSpan<
const
std::byte>> buffers)
201
{
202
Q_D(QRandomAccessAsyncFile);
203
return
d->writeFrom(offset, buffers);
204
}
205
206
QT_END_NAMESPACE
207
208
#
include
"moc_qrandomaccessasyncfile_p.cpp"
QPlatformGraphicsBufferHelper
\inmodule QtGui
qtbase
src
corelib
io
qrandomaccessasyncfile.cpp
Generated on
for Qt by
1.14.0