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

@jsenv/filesystem

Package Overview
Dependencies
Maintainers
2
Versions
95
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jsenv/filesystem - npm Package Compare versions

Comparing version 3.0.0 to 3.1.0

src/readFileSync.js

1

main.js

@@ -36,2 +36,3 @@ // we won't internalize @jsenv/url-meta

export { readFile } from "./src/readFile.js"
export { readFileSync } from "./src/readFileSync.js"
export { readEntryModificationTime } from "./src/readEntryModificationTime.js"

@@ -38,0 +39,0 @@ export { readEntryPermissions } from "./src/readEntryPermissions.js"

2

package.json
{
"name": "@jsenv/filesystem",
"version": "3.0.0",
"version": "3.1.0",
"description": "Collection of functions to interact with filesystem in Node.js",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -1,11 +0,10 @@

import { promisify } from "util"
import { readFile as readFileNode } from "fs"
import { promisify } from "node:util"
import { readFile as readFileNode } from "node:fs"
import { assertAndNormalizeFileUrl } from "./assertAndNormalizeFileUrl.js"
import { urlToFileSystemPath } from "./urlToFileSystemPath.js"
const readFilePromisified = promisify(readFileNode)
export const readFile = async (value, { as = "string" } = {}) => {
export const readFile = async (value, { as = "buffer" } = {}) => {
const fileUrl = assertAndNormalizeFileUrl(value)
const filePath = urlToFileSystemPath(fileUrl)
const buffer = await readFilePromisified(filePath)
const buffer = await readFilePromisified(new URL(fileUrl))
if (as === "buffer") {

@@ -20,3 +19,5 @@ return buffer

}
throw new Error(`as must be one of buffer,string,json, received ${as}.`)
throw new Error(
`"as" must be one of "buffer","string","json" received "${as}"`,
)
}
import { promises } from "node:fs"
import { assertAndNormalizeFileUrl } from "./assertAndNormalizeFileUrl.js"
import { urlToFileSystemPath } from "./urlToFileSystemPath.js"
import { ensureParentDirectories } from "./ensureParentDirectories.js"

@@ -12,10 +11,9 @@

const destinationUrl = assertAndNormalizeFileUrl(destination)
const destinationPath = urlToFileSystemPath(destinationUrl)
const destinationUrlObject = new URL(destinationUrl)
try {
await writeFileNode(destinationPath, content)
await writeFileNode(destinationUrlObject, content)
} catch (error) {
if (error.code === "ENOENT") {
await ensureParentDirectories(destinationUrl)
await writeFileNode(destinationPath, content)
await writeFileNode(destinationUrlObject, content)
return

@@ -22,0 +20,0 @@ }

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