forked from AlreadyBored/node-nodejs-basics
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dfc5c1a
commit cd8e881
Showing
4 changed files
with
45 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
IPA smaertS gnisu daer eb dluohs elif sihT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,13 @@ | ||
import { createReadStream } from 'fs' | ||
|
||
const streamFileToRead = createReadStream('./files/fileToRead.txt') | ||
|
||
streamFileToRead.setEncoding('UTF8'); | ||
|
||
export const read = async () => { | ||
// Write your code here | ||
}; | ||
streamFileToRead.on('data', res => { | ||
process.stdout.write(res) | ||
}) | ||
}; | ||
|
||
read() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,22 @@ | ||
import { Transform } from 'node:stream'; | ||
import { createWriteStream, createReadStream } from 'fs' | ||
|
||
export const transform = async () => { | ||
// Write your code here | ||
}; | ||
const readStream = createReadStream('./files/fileToRead.txt') | ||
const writeStream = createWriteStream('./files/fileToWrite.txt') | ||
|
||
const reverseStream = new Transform({ | ||
transform(data, encoding, callback) { | ||
const reversedData = data.toString().split("").reverse().join(""); | ||
this.push(reversedData); | ||
callback(); | ||
} | ||
}); | ||
|
||
|
||
readStream.pipe(reverseStream).pipe(writeStream).on('finish', (data, err) => { | ||
console.log(data); | ||
}); | ||
}; | ||
|
||
transform() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
import { createWriteStream } from 'fs' | ||
|
||
const streamFileToWrite = createWriteStream('./files/fileToWrite.txt') | ||
|
||
export const write = async () => { | ||
// Write your code here | ||
}; | ||
process.stdin.on('data', data => { | ||
streamFileToWrite.write(data.toString()); | ||
process.exit(); | ||
}); | ||
}; | ||
|
||
write() |