writeRecord method
Write a single dbase record.
@param record The entries to write. @throws IOException If IO error occurs. @throws DbaseFileException If the entry doesn't comply to the header.
Implementation
Future<void> writeRecord(List<dynamic> record) async {
if (record.length != header.getNumFields()) {
throw DbaseFileException(
'Wrong number of fields ${record.length} expected ${header.getNumFields()}');
}
List<int> buffer = [];
// put the 'not-deleted' marker
buffer.add(' '.codeUnitAt(0));
for (int i = 0; i < header.getNumFields(); i++) {
// convert this column to bytes
List<int> bytes;
if (record[i] == null) {
bytes = nullValues[i];
} else {
bytes = await fieldBytes(record[i], i);
// if the returned array is not the proper length
// write a null instead; this will only happen
// when the formatter handles a value improperly.
if (bytes.length != nullValues[i].length) {
bytes = nullValues[i];
}
}
buffer.addAll(bytes);
}
await write(buffer);
}