Skip to content

Commit

Permalink
Fix issue-#1049
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenny4297 committed Aug 4, 2024
1 parent 3189bf7 commit a25f7f9
Show file tree
Hide file tree
Showing 4 changed files with 1,408 additions and 1,242 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/git": "^10.0.1",
"@semantic-release/npm": "^9.0.1",
"@types/jest": "^29.0.0",
"@types/jest": "^29.5.12",
"@types/mime": "^3.0.0",
"@types/node": "^10.17.60",
"app-root-path": "^3.1.0",
Expand Down
20 changes: 18 additions & 2 deletions src/volume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -911,8 +911,17 @@ export class Volume implements FsCallbackApi, FsSynchronousApi {
readFileSync(file: TFileId, options?: opts.IReadFileOptions | string): TDataOut {
const opts = getReadFileOptions(options);
const flagsNum = flagsToNumber(opts.flag);
return this.readFileBase(file, flagsNum, opts.encoding as BufferEncoding);

// Check if the path is a directory, and throw EISDIR error if so
if (typeof file === 'string') {
if (this.existsSync(file) && this.statSync(file).isDirectory()) {
throw createError('EISDIR', 'readFile', file);
}
}

return this.readFileBase(file, flagsNum, opts.encoding as BufferEncoding);
}


readFile(id: TFileId, callback: TCallback<TDataOut>);
readFile(id: TFileId, options: opts.IReadFileOptions | string, callback: TCallback<TDataOut>);
Expand Down Expand Up @@ -1064,8 +1073,15 @@ export class Volume implements FsCallbackApi, FsSynchronousApi {
const flagsNum = flagsToNumber(opts.flag);
const modeNum = modeToNumber(opts.mode);
const buf = dataToBuffer(data, opts.encoding);

// Check if the parent path is a file, and throw ENOTDIR error if so
const parentPath = pathModule.dirname(id as string);
if (this.existsSync(parentPath) && !this.statSync(parentPath).isDirectory()) {
throw createError('ENOTDIR', 'writeFile', id as string);
}

this.writeFileBase(id, buf, flagsNum, modeNum);
}
}

writeFile(id: TFileId, data: TData, callback: TCallback<void>);
writeFile(id: TFileId, data: TData, options: opts.IWriteFileOptions | string, callback: TCallback<void>);
Expand Down
7 changes: 4 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
"declaration": true,
"skipLibCheck": true,
"noEmitHelpers": true,
"importHelpers": true
"importHelpers": true,
"types": ["node", "jest"]
},
"include": ["src"],
"exclude": ["src/__tests__", "node_modules", "lib", "es6", "es2020", "esm", "docs", "README.md"],
"include": ["src", "src/__tests__"],
"exclude": ["node_modules", "lib", "es6", "es2020", "esm", "docs", "README.md"],
"typedocOptions": {
"entryPoints": [
"src/index.ts",
Expand Down
Loading

0 comments on commit a25f7f9

Please sign in to comment.