-
Notifications
You must be signed in to change notification settings - Fork 284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fs.createWriteStream is creating file but not writing to it #1641
Comments
This problem seems to occur on both node.js version 10 and 11. I tried this too: const t = new Transform({
transform(chunk, enc, cb){
cb(null,chunk);
}
});
t.pipe(strm);
t.write('foop')
t.push('bar');
t.end(); the file gets created, but nothing gets written to it :( |
if I put a logging statement here: const t = new Transform({
transform(chunk, enc, cb){
console.log({chunk: String(chunk)}); // <<< logging
cb(null, String(chunk));
}
}); then my logging statement does log all the data that I want to go to the file, so the data is being written to the transform stream but not to the file! :( |
not reproducible with v10.5 on mac. which platform do you use? const fs = require('fs');
const strm = fs.createWriteStream('ore.txt');
strm.write('foop\n');
strm.write('bop\n');
strm.end() $ node -v
$ |
Yeah my current guess is that some error is failing silently in the program before it has a chance to write all the files out...but I am not sure yet..I am on Ubuntu...Node version 10/11. |
@gireeshpunathil ughh it was a simple case of calling thanks |
@ORESoftware - went through nodejs/node#2468 , thanks for the full context! As I see it, the event infrastructure (event loop) could be in probable states when process.exit() is called:
This also covers the many-times-reported issue of truncated console output on CLI programs (ref: There is something we can do to improve the user experience on case 3, don't know what is the right semantics though. |
@gireeshpunathil for the purposes of this feature, what would be the difference between 2 and 3? |
@ORESoftware - In event driven programming, a program would have (ideally) one or more event registrations at any given point in time. In the most common use cases, the characteristic feature of these events are:
classical example is the webserver's service loop ( It is an over-kill to inform / warn about the presence of such a pending event handler on process.exit. In case 3, and event is registered, as well as triggered, and being actioned upon. We are exiting in the middle - which warrants some form of functional (or documented) support. |
let fs = require('fs')
let { Console } = require('console')
// fs.writeFileSync('./node/test/outputs/searches.log', 'tetet')
// fs.writeFileSync('./node/test/outputs/searches.log.error.log', 'teteet')
const output = fs.createWriteStream('./node/test/outputs/searches.log');
const errorOutput = fs.createWriteStream('./node/test/outputs/searches.log.error.log');
console = new Console(output, errorOutput);
// let query = "🌿 🌻 🍓"
let query = "one two three"
// let query = "LOL LMAO LMFAO"
let words = query.split(' ')
let debug = global.debug || false
let smarts = require('smarts')()
let ps = require('prettyjson')
console.log('\n start \n')
let args = {
array: words,
combinations: [],
combinationsA: []
}
let codes = [0,1]
let permutationsCodes = getVariablePermutations(codes, args.array.length)
let permutations = []
for(permutationCodeIndex in permutationsCodes){
permutations[permutationCodeIndex] = []
for(includeIndex in permutationsCodes[permutationCodeIndex]){
if(permutationsCodes[permutationCodeIndex][includeIndex]){
permutations[permutationCodeIndex].push(args.array[includeIndex])
// console.log('args.array[includeIndex] ', args.array[includeIndex])
}
}
}
let searchPermutations = []
let i = 0
for(permutationIndex in permutations){
// generate the insertion sequence for regex or any other symbols, [0,1,1,0], [0,0,1,0] etc..
// we use length + 1 to create the last index trailing regex edge case
let insertionCodes = getVariablePermutations(codes, permutations[permutationIndex].length+1)
for(insertionCodeIndex in insertionCodes){
// create the array for the current search permutation
searchPermutations.push([])
// iterator for the current search permutation section
let b = 0
// create first search permutation section
searchPermutations[i].push([])
// loop over insertion indexes to know when to split or insert into the search query
for(insertionIndex in insertionCodes[insertionCodeIndex]){
// if the insertion index is less than the length then we're within the last index edge case for trailing regex
if(insertionIndex < permutations[permutationIndex].length){
// if the insertion index is not 0 then we insert something, in this case only 0/1 where 1 is a regex for match any .*
if(insertionCodes[insertionCodeIndex][insertionIndex]){
// if the insertion index isn't 0, we add two more arrays to split away from the previous search string for the new regex section plus also add a new search string section
if(insertionIndex !== '0'){
b++
searchPermutations[i].push([])
searchPermutations[i][b].push('/.*/')
b++
searchPermutations[i].push([])
searchPermutations[i][b].push(permutations[permutationIndex][insertionIndex])
}
// if we are at the start of the search string we exhibit the leading regex edge case behaviour where you don't need to create a new array for the regex
else {
searchPermutations[i][b].push('/.*/')
b++
searchPermutations[i].push([permutations[permutationIndex][insertionIndex]])
}
}
// if there's nothing to insert, we push the next search string into the current non-disturbed sub-search string array
else {
searchPermutations[i][b].push(permutations[permutationIndex][insertionIndex])
}
}
// else if the insertion index is greater than the length of the search string permutation then we exhibit the last index edge case behaviour for trailing regex
else if(insertionCodes[insertionCodeIndex][insertionIndex]){
b++
searchPermutations[i].push([])
searchPermutations[i][b].push('/.*/')
}
}
i++
}
}
for(test in searchPermutations){
console.log(searchPermutations[test])
}
console.log(searchPermutations.length)
function getVariablePermutations(list, maxLen) {
// Copy initial values as arrays
if(maxLen == 0) return []
var perm = list.map(function(val) {
return [val];
});
// Our permutation generator
var generate = function(perm, maxLen, currLen) {
// Reached desired length
if (currLen === maxLen) {
return perm;
}
// For each existing permutation
for (var i = 0, len = perm.length; i < len; i++) {
var currPerm = perm.shift();
// Create new permutation
for (var k = 0; k < list.length; k++) {
perm.push(currPerm.concat(list[k]));
}
}
// Recurse
return generate(perm, maxLen, currLen + 1);
};
// Start with size 1 because of initial values
return generate(perm, maxLen, 1);
};
process.exit() this is too soon??!?!?!?!?! I fixed this issue by commenting the process.exit, but what?? |
Is there a solution for this ? I'm trying to log some stuff into a file using fs.createWriteStream before exiting the process. |
@szekelygobe
|
@provCristianMaluenda thank you so much for this! |
I have this:
for some reason, the file gets created, but no data gets written to the file. Why would that happen?
The text was updated successfully, but these errors were encountered: