LazyWriter
Source code in src/msglc/writer.py
| Python | |
|---|---|
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 | |
__init__(buffer_or_path, packer=None, *, fs=None)
It is possible to provide a custom packer object to be used for packing the object.
However, this packer must be compatible with the msgpack packer.
The buffer_or_path can be
1. a plain str pointing to a file on local filesystem, or a file on target filesystem if fs is provided,
2. a UPath object that points to a file on supported filesystem (either local or remote),
3. a IO object that has .tell(), .seek(), .write() methods, this object must have random write access.
Warning:
Some of backend filesystems only supports sequential write rather than random write thus not all filesystems
supported by UPath can be used.
One must always check if the target filesystem supports random write access.
If not, the most generic approach is to provide a plain string for buffer_or_path and explicitly assign a fs object.
In this case, a local cache will be used to temporarily handle the serialization and the binary blob
will be uploaded to the remote once everything is processed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
buffer_or_path
|
str | UPath | BufferWriter
|
target buffer or file path |
required |
packer
|
Packer
|
packer object to be used for packing the object |
None
|
fs
|
FileSystem | None
|
|
None
|
Source code in src/msglc/writer.py
write(obj)
This function is used to write the object to the file.
Only one write is allowed. The function raises a ValueError if it is called more than once.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
the object to be written to the file |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the function is called more than once |