| 26 | } = require('internal/errors'); |
| 27 | |
| 28 | function readFileAfterRead(err, bytesRead) { |
| 29 | const context = this.context; |
| 30 | |
| 31 | if (err) |
| 32 | return context.close(err); |
| 33 | |
| 34 | if (context.checkOverflow) { |
| 35 | context.checkOverflow = false; |
| 36 | |
| 37 | if (bytesRead !== 0) { |
| 38 | return context.close(createReadFileBufferTooSmallError( |
| 39 | context.bufferByteLengthName, |
| 40 | context.buffer.byteLength, |
| 41 | )); |
| 42 | } |
| 43 | |
| 44 | return context.close(); |
| 45 | } |
| 46 | |
| 47 | context.pos += bytesRead; |
| 48 | |
| 49 | if (context.userBuffer) { |
| 50 | if (context.pos === context.size || bytesRead === 0) { |
| 51 | context.close(); |
| 52 | } else { |
| 53 | context.read(); |
| 54 | } |
| 55 | return; |
| 56 | } |
| 57 | |
| 58 | if (context.pos === context.size || bytesRead === 0) { |
| 59 | context.close(); |
| 60 | } else { |
| 61 | if (context.size === 0) { |
| 62 | // Unknown size, just read until we don't get bytes. |
| 63 | const buffer = bytesRead === kReadFileUnknownBufferLength ? |
| 64 | context.buffer : context.buffer.slice(0, bytesRead); |
| 65 | ArrayPrototypePush(context.buffers, buffer); |
| 66 | } |
| 67 | context.read(); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | function readFileAfterClose(err) { |
| 72 | const context = this.context; |