Comments (1)
I've changed the code to piping streams, with a transform stream in between.
function createFile(filepath, extension){
if(filepath.endsWith(extension)){
let filename = path.basename(filepath, extension);
const rs = fs.createReadStream(filepath);
rs.setEncoding("utf8");
rs.on("data", () =>{});
rs.on("end", ()=>{});
rs.on("error", (err) =>{
console.error(`ReadStream encountered an error: ${err}`);
process.exit(-1);
});
let ws = fs.createWriteStream(path.join(outputPath, filename.replace(/\s+/g, '_')+".html"));
ws.on("finish", ()=>{});
ws.on("error", (err) =>{
console.error(`WriteStream encountered an error: ${err}`);
ws.end();
process.exit(-1);
});
const toHtmlStream = new Transform({
objectMode: true,
transform(chunk, encoding, callback){
this.push(htmlContent(chunk.toString(), filename, extension));
return callback();
},
});
toHtmlStream.on('error', (err) =>{
console.error(`toHtmlStream encountered an error: ${err}`);
process.exit(-1);
});
//Piping data
rs.pipe(toHtmlStream).pipe(ws);
}
}
But, I am not entirely sure if this is the right way to handle errors and end streams.
from sitegen.
Related Issues (19)
- Installation problem. HOT 1
- Failed HTML markup validation for index.html. HOT 1
- Add more validaiton on reading file extensions. HOT 1
- Add Markdown support.
- Expand copyright info HOT 1
- Improve error handling HOT 1
- Use path module to construct/inspect paths HOT 1
- Don't use callbacks with *Sync methods HOT 1
- Feature - add support for inline <code> blocks in Markdown HOT 1
- Feature - add support for horizontal rule in Markdown HOT 1
- New SSG feature: adding option --config with Config File
- Enhancement: Markdown Features based on Docusaurus
- Feature: Apply syntax highlights to in Markdown code blocks
- Feature: Markdown Front Matter support HOT 2
- Feature: MDX and React Component support
- Feature: Markdown Admonitions
- Copy feature for generated code blocks
- New Test. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sitegen.