seek()在javascript/node.js中是否等效?

seek()在javascript/node.js中是否等效?,javascript,node.js,file-io,Javascript,Node.js,File Io,我目前正在尝试使用fs module for node.js读取一些文件。 由于它缺少我习惯使用的函数(fseek(),getline()…),所以我正在创建另一个模块来恢复它们。(C stdio.h的node.js副本) 我的简单问题是: seek()是否以其他名称存在,或者我是否需要重新实现几乎所有函数才能拥有它?此软件包值得一看: 除了包裹,我能找到的最接近的是: 或者在fs.read上使用这些参数 length is an integer specifying the number o

我目前正在尝试使用fs module for node.js读取一些文件。 由于它缺少我习惯使用的函数(fseek(),getline()…),所以我正在创建另一个模块来恢复它们。(C stdio.h的node.js副本)

我的简单问题是:


seek()是否以其他名称存在,或者我是否需要重新实现几乎所有函数才能拥有它?

此软件包值得一看:

除了包裹,我能找到的最接近的是: 或者在fs.read上使用这些参数

length is an integer specifying the number of bytes to read.

position is an integer specifying where to begin reading from in the file. If position is null, data will be read from the current file position.

在node.js中,
seek
功能包含在
read
功能中。使用
fs.read
函数时,有一个名为
position
的参数,用作搜索位置

如果要写入文件,函数
fs.write
也有
position
参数

检查此处的文档:

NodeJS v6.5.0不再具有
length
属性;它已被
开始
结束
属性所取代,这两个属性分别决定了文件应从哪一行读取和从哪一行读取。我在回答中包括了一个例子。注意:“如果位置是整数,文件位置将保持不变。”。当您传入一个位置并读取一些字节时,文件位置不会因读取量而移动。继续增量读取的唯一方法是跟踪读取的位置+字节,并保持从新位置读取。