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