aboutsummaryrefslogtreecommitdiffstats
path: root/doc/codesnippets/doc/src/snippets/code/src_corelib_io_qiodevice.cpp
blob: 6b791bfc2c3ce2e8cca011621ff0a5c03c3fbc86 (plain)
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
//! [0]
gzip = QProcess()
gzip.start("gzip", ["-c"])
if not gzip.waitForStarted():
    return False

gzip.write("uncompressed data")

compressed = QByteArray()
while gzip.waitForReadyRead():
    compressed += gzip.readAll()
//! [0]


//! [1]
def bytesAvailable(self):
    return buffer.size() + QIODevice.bytesAvailable()
//! [1]


//! [2]
file = QFile("box.txt")
if file.open(QFile.ReadOnly):
    buf = file.readLine(1024)
    if buf.size():
        # the line is available in buf
//! [2]


//! [3]
def canReadLine(self):
    return buffer.contains('\n') or QIODevice.canReadLine()
//! [3]


//! [4]
def isExeFile(file_):
    buf = file_.peek(2)
    if buf.size() == 2:
        return buf[0] == 'M' and buf[1] == 'Z'
    return False
//! [4]


//! [5]
def isExeFile(file_):
    return file_.peek(2) == "MZ"
//! [5]