Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
A simple promise-based wrapper for file operations that treats files as objects.
A simple promise-based wrapper for file operations that treats files as objects.
File = require 'fobject'
configFile = new File('config.json')
configFile.read().done((data) ->
console.log "contents of #{configFile.path}: #{data}"
)
Also, this includes a 2nd wrapper that extends the first and lets you cache the contents of the file directly in the object
File = require 'fobject/cached'
logFile = new File('log')
logFile.load().then( ->
console.log logFile.content # print out the logs
logFile.content += 'this is a demo\n' # add a line
).then(
logFile.save
).done( ->
console.log('the logs are saved, and since we only added to the string, the
`File.save()` call was optimized into a single `append()`')
)
The default fs module has a really ugly interface (including sync and async copies of almost every function) and doesn't make it easy to work with files that may or may not actually be written to the file-system. fobject abstracts out interaction with the file system so if you want to implement caching, or work with files without writing them to the disk, or whatever else you want: you can do so easily.
Name | Type | Argument | Default | Description |
---|---|---|---|---|
path | String | The path to the file. This will be resolved to an absolute path, so even if you change your cwd you can still access the same file. | ||
options.base | String |
<optional> | ./ | Used for relative pathing. This will not be resolved to an absolute path. Typically where a glob starts. |
Append data
to the file
Name | Type | Argument | Default | Description |
---|---|---|---|---|
data | String | Buffer | |||
options.encoding | String | null |
<optional> | 'utf8' | ignored if data is a buffer |
options.mode | Number |
<optional> | 438 | default is 0666 in Octal |
options.flag | String |
<optional> | 'w' |
Get the dirname of the file
Get the extension of a file
Read from the file
Name | Type | Argument | Default | Description |
---|---|---|---|---|
options.encoding | String | null |
<optional> | null | |
options.flag | String |
<optional> | 'r' |
Rename the file
Name | Type | Description |
---|---|---|
newPath | String | The new path for the file. Will be resolved relative to File.base. |
Return a Stat object for the file
Delete the file
Write data
to the file
Name | Type | Argument | Default | Description |
---|---|---|---|---|
data | String | Buffer | |||
options.encoding | String | null |
<optional> | 'utf8' | ignored if data is a buffer |
options.mode | Number |
<optional> | 438 | default is 0666 in Octal |
options.flag | String |
<optional> | 'w' |
generated with docme
FAQs
A simple promise-based wrapper for file operations that treats files as objects.
The npm package fobject receives a total of 3,423 weekly downloads. As such, fobject popularity was classified as popular.
We found that fobject demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.