我目前正在尝试使用fs模块为node.js读取一些文件。 由于它缺少我曾经使用的函数(fseek(),getline()...),我创建了另一个模块来取回它们。 (C stdio.h的node.js副本)。
我的简单问题是:
seek()是否存在于其他名称中,或者我是否需要重新填充几乎所有函数才能拥有它?
答案 0 :(得分:11)
在node.js中,seek
功能包含在read
功能中。当您使用fs.read
函数时,会有一个名为position
的参数,作为搜索位置。
如果您想要写入文件,则函数fs.write
也会有position
参数。
查看此处的文档: https://nodejs.org/api/fs.html#fs_fs_read_fd_buffer_offset_length_position_callback
答案 1 :(得分:3)
这个包值得看: https://npmjs.org/package/fs-ext
除了包裹之外,我能找到的最近的是: http://nodejs.org/api/fs.html#fs_fs_createreadstream_path_options 或在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.