Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

can-write-to-dir

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

can-write-to-dir - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

7

CHANGELOG.md
# can-write-to-dir
## 1.1.0
### Minor Changes
- bba9985: graceful-fs and mz removed from dependencies.
## 1.0.0
### Major Changes
- 48d36f2: Project created.

36

index.js
'use strict'
const gracefulFs = require('graceful-fs')
const defaultFS = require('fs')
const pathTemp = require('path-temp')
module.exports = (dir, customFs) => {
const fs = customFs || gracefulFs
return new Promise((resolve, reject) => {
const tempFile = pathTemp(dir)
fs.writeFile(tempFile, '', 'utf8', err => {
if (!err) {
fs.unlink(tempFile, () => {})
resolve(true)
return
}
if (err.code === 'EACCES' || err.code === 'EPERM' || err.code === 'EROFS') {
resolve(false)
return
}
reject(err)
})
})
module.exports = async (dir, customFS) => {
const fs = customFS || defaultFS
const tempFile = pathTemp(dir)
try {
await fs.promises.writeFile(tempFile, '', 'utf8')
fs.promises.unlink(tempFile).catch(() => {})
return true
} catch (err) {
if (err.code === 'EACCES' || err.code === 'EPERM' || err.code === 'EROFS') {
return false
}
throw err
}
}
module.exports.sync = (dir, customFs) => {
const fs = customFs || gracefulFs
module.exports.sync = (dir, customFS) => {
const fs = customFS || defaultFS
const tempFile = pathTemp(dir)

@@ -27,0 +23,0 @@ try {

{
"name": "can-write-to-dir",
"version": "1.0.1",
"version": "1.1.0",
"description": "Returns true if the current process has permission to write to the specified directory",

@@ -28,3 +28,2 @@ "main": "index.js",

"dependencies": {
"graceful-fs": "^4.2.4",
"path-temp": "^2.0.0"

@@ -34,5 +33,5 @@ },

"package-preview": "3.0.0",
"standard": "^16.0.1",
"tape": "^5.0.1"
"standard": "^16.0.3",
"tape": "^5.1.1"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc