Skip to content
This repository was archived by the owner on Jul 2, 2024. It is now read-only.

Commit 8cc85b9

Browse files
Merge pull request #11 from g-script/fix/fs-read-sync-usage
Fix fs.readSync usage for Node version 11 and below
2 parents e45e005 + 6c94b4d commit 8cc85b9

File tree

4 files changed

+8
-18
lines changed

4 files changed

+8
-18
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class Tail extends Readable {
186186
} else {
187187
const buff = Buffer.alloc(fs.fstatSync(this.target).size)
188188

189-
fs.readSync(this.target, buff, { position: 0 })
189+
fs.readSync(this.target, buff, 0, buff.length, 0)
190190

191191
data = buff.toString(this.options.encoding)
192192
}

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "better-tail",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"description": "Node.js implementation of UNIX tail command using streams. No dependencies.",
55
"main": "index.js",
66
"files": [
@@ -12,8 +12,7 @@
1212
"scripts": {
1313
"lint": "standard index.js test/index.js",
1414
"fix-lint": "npm run lint -- --fix",
15-
"test": "mocha -b",
16-
"preversion": "npm run minify"
15+
"test": "mocha -b"
1716
},
1817
"repository": {
1918
"type": "git",

test/index.js

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ describe('better-tail', function () {
141141
const data = []
142142

143143
new Tail(target).on('data', (line) => {
144-
console.log(line.toString('utf8'))
145144
data.push(line)
146145
}).on('end', () => {
147146
expect(data[0]).to.be.instanceof(Buffer, 'Expected data to be an instance of Buffer')
@@ -174,9 +173,7 @@ describe('better-tail', function () {
174173
const buff = Buffer.alloc(bytes)
175174

176175
// Read file last N bytes
177-
fs.readSync(corpus.fd, buff, {
178-
position: contentByteLength - bytes
179-
})
176+
fs.readSync(corpus.fd, buff, 0, buff.length, contentByteLength - bytes)
180177

181178
const data = []
182179

@@ -214,9 +211,7 @@ describe('better-tail', function () {
214211
const buff = Buffer.alloc(contentByteLength - startAtByte)
215212

216213
// Read file from picked byte
217-
fs.readSync(corpus.fd, buff, {
218-
position: startAtByte
219-
})
214+
fs.readSync(corpus.fd, buff, 0, buff.length, startAtByte)
220215

221216
const data = []
222217

@@ -260,9 +255,7 @@ describe('better-tail', function () {
260255
const buff = Buffer.allocUnsafe(linesByteLength)
261256

262257
// Read file from last N lines byte length
263-
fs.readSync(corpus.fd, buff, {
264-
position: contentByteLength - linesByteLength
265-
})
258+
fs.readSync(corpus.fd, buff, 0, buff.length, contentByteLength - linesByteLength)
266259

267260
const data = []
268261

@@ -306,9 +299,7 @@ describe('better-tail', function () {
306299
const linesByteLength = Buffer.byteLength(contentLines.slice(lines).join('\r\n'))
307300
const buff = Buffer.allocUnsafe(linesByteLength)
308301

309-
fs.readSync(corpus.fd, buff, {
310-
position: contentByteLength - linesByteLength
311-
})
302+
fs.readSync(corpus.fd, buff, 0, buff.length, contentByteLength - linesByteLength)
312303

313304
const data = []
314305

0 commit comments

Comments
 (0)