This won’t leave created file descriptors open. If you need the file descriptor for further processing, remember to close it when you finish all your handling. OpenSync(path)returns a file descriptor: const Fs = require('fs')Ĭonst fileDescriptor = Fs.openSync(path, 'a') Please consider using the asynchronous approach. Some trackers require you to add information in the torrent file such as private torrent, a comment to identify the tracker and the like. You may need to make a description too and a specific title. Notice: the synchronous way will block the Node.js event loop while traversing the file system and creating the file. Some trackers demand that you use certain file names, structures, formats and the like. You can implement the synchronous approach with modules already integrated into the fs module from Node.js: const Fs = require('fs') Sweet!Īlso, it won’t override an existing file. It handles the creation of missing directories automatically. The fs-extra package includes the extra ensureFile(path) method which creates the file at path: const Fs = require('fs-extra')Ī nice benefit of ensureFile is that it creates all missing directories along the path. fs-extra provides the same API as the Node.js fs module and additional convenience methods. you could interface with an external application, interface with node.js wrappers for a C library or use a native node.js torrent implementation. This asynchronous way of creating an empty file uses the helper library fs-extra.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |