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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
// Copyright (C) 2025 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
// Qt-Security score:significant reason:default
#include "qrandomaccessasyncfile_p.h"
#include "qrandomaccessasyncfile_p_p.h"
QT_BEGIN_NAMESPACE
QRandomAccessAsyncFile::QRandomAccessAsyncFile(QObject *parent)
: QObject{*new QRandomAccessAsyncFilePrivate, parent}
{
d_func()->init();
}
QRandomAccessAsyncFile::~QRandomAccessAsyncFile()
{
close();
}
bool QRandomAccessAsyncFile::open(const QString &filePath, QIODeviceBase::OpenMode mode)
{
Q_D(QRandomAccessAsyncFile);
return d->open(filePath, mode);
}
void QRandomAccessAsyncFile::close()
{
Q_D(QRandomAccessAsyncFile);
d->close();
}
qint64 QRandomAccessAsyncFile::size() const
{
Q_D(const QRandomAccessAsyncFile);
return d->size();
}
/*!
\internal
Reads at maximum \a maxSize bytes, starting from \a offset.
The data is written to the internal buffer managed by the returned
QIOOperation object.
//! [returns-qiooperation]
Returns a QIOOperation object that would emit a QIOOperation::finished()
signal once the operation is complete.
//! [returns-qiooperation]
*/
QIOReadOperation *QRandomAccessAsyncFile::read(qint64 offset, qint64 maxSize)
{
Q_D(QRandomAccessAsyncFile);
return d->read(offset, maxSize);
}
/*!
\internal
\overload
Reads the data from the file, starting from \a offset, and stores it into
\a buffer.
The amount of bytes to be read from the file is determined by the size of
the buffer. Note that the actual amount of read bytes can be less than that.
This operation does not take ownership of the provided buffer, so it is the
user's responsibility to make sure that the buffer is valid until the
returned QIOOperation completes.
\note The buffer might be populated from different threads, so the user
application should not access it until the returned QIOOperation completes.
\include qrandomaccessasyncfile.cpp returns-qiooperation
*/
QIOVectoredReadOperation *
QRandomAccessAsyncFile::readInto(qint64 offset, QSpan<std::byte> buffer)
{
Q_D(QRandomAccessAsyncFile);
return d->readInto(offset, buffer);
}
/*!
\internal
Reads the data from the file, starting from \a offset, and stores it into
\a buffers.
The amount of bytes to be read from the file is determined by the sum of
sizes of all buffers. Note that the actual amount of read bytes can be less
than that.
This operation does not take ownership of the provided buffers, so it is the
user's responsibility to make sure that the buffers are valid until the
returned QIOOperation completes.
\note The buffers might be populated from different threads, so the user
application should not access them until the returned QIOOperation completes.
\include qrandomaccessasyncfile.cpp returns-qiooperation
*/
QIOVectoredReadOperation *
QRandomAccessAsyncFile::readInto(qint64 offset, QSpan<const QSpan<std::byte>> buffers)
{
Q_D(QRandomAccessAsyncFile);
return d->readInto(offset, buffers);
}
/*!
\internal
Writes \a data into the file, starting from \a offset.
The \a data array is copied into the returned QIOOperation object.
\include qrandomaccessasyncfile.cpp returns-qiooperation
*/
QIOWriteOperation *QRandomAccessAsyncFile::write(qint64 offset, const QByteArray &data)
{
Q_D(QRandomAccessAsyncFile);
return d->write(offset, data);
}
/*!
\internal
\overload
Writes \a data into the file, starting from \a offset.
The \a data array is moved into the returned QIOOperation object.
\include qrandomaccessasyncfile.cpp returns-qiooperation
*/
QIOWriteOperation *QRandomAccessAsyncFile::write(qint64 offset, QByteArray &&data)
{
Q_D(QRandomAccessAsyncFile);
return d->write(offset, std::move(data));
}
/*!
\internal
\overload
Writes the content of \a buffer into the file, starting from \a offset.
This operation does not take ownership of the provided buffer, so it is the
user's responsibility to make sure that the buffer is valid until the
returned QIOOperation completes.
\note The buffer might be accessed from different threads, so the user
application should not modify it until the returned QIOOperation completes.
*/
QIOVectoredWriteOperation *
QRandomAccessAsyncFile::writeFrom(qint64 offset, QSpan<const std::byte> buffer)
{
Q_D(QRandomAccessAsyncFile);
return d->writeFrom(offset, buffer);
}
/*!
\internal
Writes the content of \a buffers into the file, starting from \a offset.
This operation does not take ownership of the provided buffers, so it is the
user's responsibility to make sure that the buffers are valid until the
returned QIOOperation completes.
\note The buffers might be accessed from different threads, so the user
application should not modify them until the returned QIOOperation
completes.
*/
QIOVectoredWriteOperation *
QRandomAccessAsyncFile::writeFrom(qint64 offset, QSpan<const QSpan<const std::byte>> buffers)
{
Q_D(QRandomAccessAsyncFile);
return d->writeFrom(offset, buffers);
}
QT_END_NAMESPACE
#include "moc_qrandomaccessasyncfile_p.cpp"
|