(path: string, flags: FileFlag, mode: number, cb: BFSCallback<File>)
| 488 | } |
| 489 | |
| 490 | public open(path: string, flags: FileFlag, mode: number, cb: BFSCallback<File>): void { |
| 491 | // Try and get the file's contents |
| 492 | this._client.readFile(path, (error, content, dbStat) => { |
| 493 | if (error) { |
| 494 | // If the file's being opened for reading and doesn't exist, return an |
| 495 | // error |
| 496 | if (flags.isReadable()) { |
| 497 | cb(this.convert(error, path)); |
| 498 | } else { |
| 499 | switch (error.status) { |
| 500 | // If it's being opened for writing or appending, create it so that |
| 501 | // it can be written to |
| 502 | case Dropbox.ApiError.NOT_FOUND: |
| 503 | const ab = new ArrayBuffer(0); |
| 504 | return this._writeFileStrict(path, ab, (error2: ApiError, stat?: Dropbox.File.Stat) => { |
| 505 | if (error2) { |
| 506 | cb(error2); |
| 507 | } else { |
| 508 | const file = this._makeFile(path, flags, stat!, arrayBuffer2Buffer(ab)); |
| 509 | cb(null, file); |
| 510 | } |
| 511 | }); |
| 512 | default: |
| 513 | return cb(this.convert(error, path)); |
| 514 | } |
| 515 | } |
| 516 | } else { |
| 517 | // No error |
| 518 | let buffer: Buffer; |
| 519 | // Dropbox.js seems to set `content` to `null` rather than to an empty |
| 520 | // buffer when reading an empty file. Not sure why this is. |
| 521 | if (content === null) { |
| 522 | buffer = emptyBuffer(); |
| 523 | } else { |
| 524 | buffer = arrayBuffer2Buffer(content!); |
| 525 | } |
| 526 | const file = this._makeFile(path, flags, dbStat!, buffer); |
| 527 | return cb(null, file); |
| 528 | } |
| 529 | }); |
| 530 | } |
| 531 | |
| 532 | public _writeFileStrict(p: string, data: ArrayBuffer, cb: BFSCallback<Dropbox.File.Stat>): void { |
| 533 | const parent = path.dirname(p); |
nothing calls this directly
no test coverage detected