File: deprecated.md

package info (click to toggle)
python-pyzstd 0.19.1-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 496 kB
  • sloc: python: 5,754; makefile: 4
file content (106 lines) | stat: -rw-r--r-- 2,933 bytes parent folder | download
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
# pyzstd module: deprecations

## `compress_stream`

```python
# before
with io.open(input_file_path, 'rb') as ifh:
    with io.open(output_file_path, 'wb') as ofh:
        compress_stream(ifh, ofh, level_or_option=5)

# after
with io.open(input_file_path, 'rb') as ifh:
    with pyzstd.open(output_file_path, 'w', level_or_option=5) as ofh:
        shutil.copyfileobj(ifh, ofh)
```

```{hint}
Instead of the `read_size` and `write_size` parameters, you can use
`shutil.copyfileobj`'s `length` parameter.
```

Alternatively, you can use `ZstdCompressor` to have more control:

```python
# after: more complex alternative
with io.open(input_file_path, 'rb') as ifh:
    with io.open(output_file_path, 'wb') as ofh:
        compressor = ZstdCompressor(level_or_option=5)
        compressor._set_pledged_input_size(pledged_input_size)  # optional
        while data := ifh.read(read_size):
            ofh.write(compressor.compress(data))
            callback_progress(ifh.tell(), ofh.tell())  # optional
        ofh.write(compressor.flush())
```

_Deprecated in version 0.17.0._

## `decompress_stream`

```python
# before
with io.open(input_file_path, 'rb') as ifh:
    with io.open(output_file_path, 'wb') as ofh:
        decompress_stream(ifh, ofh)

# after
with pyzstd.open(input_file_path) as ifh:
    with io.open(output_file_path, 'wb') as ofh:
        shutil.copyfileobj(ifh, ofh)
```

```{hint}
Instead of the `read_size` and `write_size` parameters, you can use
`shutil.copyfileobj`'s `length` parameter.
```

Alternatively, you can use `EndlessZstdDecompressor` to have more control:

```python
# after: more complex alternative
with io.open(input_file_path, 'rb') as ifh:
    with io.open(output_file_path, 'wb') as ofh:
        decompressor = EndlessZstdDecompressor()
        while True:
            if decompressor.needs_input:
                data = input_stream.read(read_size)
                if not data:
                    break
            else:
                data = b""
            ofh.write(decompressor.decompress(data, write_size))
            callback_progress(ifh.tell(), ofh.tell())  # optional
        if not decompressor.at_frame_edge:
            raise ValueError("zstd data ends in an incomplete frame")
```

_Deprecated in version 0.17.0._

## `richmem_compress`

```python
# before
data_out = pyzstd.richmem_compress(data_in, level_or_option=5)

# after
data_out = pyzstd.compress(data_in, level_or_option=5)
```

_Deprecated in version 0.18.0._

## `RichMemZstdCompressor`

```python
# before
compressor = pyzstd.RichMemZstdCompressor(level_or_option=5)
data_out1 = compressor.compress(data_in1)
data_out2 = compressor.compress(data_in2)
data_out3 = compressor.compress(data_in3)

# after
data_out1 = pyzstd.compress(data_in1, level_or_option=5)
data_out2 = pyzstd.compress(data_in2, level_or_option=5)
data_out3 = pyzstd.compress(data_in3, level_or_option=5)
```

_Deprecated in version 0.18.0._