* Reads the contents of a symlink if it exists, otherwise returns null. * Rethrows errors that aren't related to file existence. * * @param {string} filename - The path to the symlink. * @param {Object} [opts={ encoding: 'buffer' }] - Options for reading the symlink. * @returns {Promi
(filename, opts = { encoding: 'buffer' })
| 285 | * @returns {Promise<Buffer|null>} - The symlink target, or `null` if it doesn't exist. |
| 286 | */ |
| 287 | async readlink(filename, opts = { encoding: 'buffer' }) { |
| 288 | // Note: FileSystem.readlink returns a buffer by default |
| 289 | // so we can dump it into GitObject.write just like any other file. |
| 290 | try { |
| 291 | const link = await this._readlink(filename, opts) |
| 292 | return Buffer.isBuffer(link) ? link : Buffer.from(link) |
| 293 | } catch (err) { |
| 294 | if (err.code === 'ENOENT' || (err.code || '').includes('ENS')) { |
| 295 | return null |
| 296 | } |
| 297 | throw err |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | /** |
| 302 | * Write the contents of buffer to a symlink. |
no test coverage detected