| 4 | } |
| 5 | |
| 6 | readFileSync(fileName, options = {}) { |
| 7 | const encoding = typeof options === 'string' ? options : options.encoding; |
| 8 | const virtualFileName = normalizeFilename(fileName); |
| 9 | |
| 10 | const data = this.fileData[virtualFileName]; |
| 11 | if (data == null) { |
| 12 | throw new Error( |
| 13 | `File '${virtualFileName}' not found in virtual file system`, |
| 14 | ); |
| 15 | } |
| 16 | |
| 17 | if (encoding) { |
| 18 | // return a string |
| 19 | return typeof data === 'string' ? data : data.toString(encoding); |
| 20 | } |
| 21 | |
| 22 | return Buffer.from(data, typeof data === 'string' ? 'base64' : undefined); |
| 23 | } |
| 24 | |
| 25 | writeFileSync(fileName, content) { |
| 26 | this.fileData[normalizeFilename(fileName)] = content; |