@@ -47,12 +47,12 @@ module.exports.createWriteStream = (options) => {
47
47
// create a new tempfile for this placetype
48
48
if ( ! _ . has ( metadata , placetype ) ) {
49
49
const tmpFileName = tmp . tmpNameSync ( )
50
+ const sink = fs . createWriteStream ( tmpFileName )
51
+ const closed = new Promise ( ( resolve , reject ) => sink . on ( 'error' , reject ) . on ( 'close' , resolve ) )
50
52
const store = {
51
53
path : tmpFileName ,
52
- writable : miss . pipeline . obj (
53
- csv ( ) ,
54
- fs . createWriteStream ( tmpFileName )
55
- )
54
+ writable : miss . pipeline . obj ( csv ( ) , sink ) ,
55
+ closed
56
56
}
57
57
metadata [ placetype ] = store
58
58
}
@@ -66,15 +66,13 @@ module.exports.createWriteStream = (options) => {
66
66
}
67
67
68
68
// called at the end
69
- const flush = ( done ) => {
69
+ const flush = async ( done ) => {
70
70
// write meta file(s)
71
71
if ( options . nometa !== true ) {
72
- _ . each ( metadata , ( store , placetype ) => {
73
- // end writing to file
72
+ // write CSV meta files
73
+ _ . each ( metadata , async ( store , placetype ) => {
74
74
store . writable . end ( )
75
-
76
- // write CSV meta files
77
- // @todo : try getting this to work with pure streams?
75
+ await store . closed
78
76
const metaFilename = convention . metaFilename ( options . collection , placetype , options . vintage )
79
77
const header = { name : path . join ( 'meta' , metaFilename ) }
80
78
pack . entry ( header , fs . readFileSync ( store . path ) )
0 commit comments