Convert a string to a null-terminated bytes object.
(s, length, encoding, errors)
| 154 | #--------------------------------------------------------- |
| 155 | |
| 156 | def stn(s, length, encoding, errors): |
| 157 | """Convert a string to a null-terminated bytes object. |
| 158 | """ |
| 159 | if s is None: |
| 160 | raise ValueError("metadata cannot contain None") |
| 161 | s = s.encode(encoding, errors) |
| 162 | return s[:length] + (length - len(s)) * NUL |
| 163 | |
| 164 | def nts(s, encoding, errors): |
| 165 | """Convert a null-terminated bytes object to a string. |