static int wolfSSH_SFTP_buffer_read(WOLFSSH* ssh, WS_SFTP_BUFFER* buffer,
        int readSz)
{
    int ret;

    if (buffer == NULL || ssh == NULL) {
        return WS_FATAL_ERROR;
    }

    if (readSz == 0) {
        return 0;
    }

    if (buffer->data == NULL) {
        buffer->idx = 0;
        buffer->sz  = readSz;
        buffer->data = (byte*)WMALLOC(buffer->sz, ssh->ctx->heap,
               DYNTYPE_BUFFER);
        if (buffer->data == NULL) {
            return WS_MEMORY_E;
        }
    }

    do {
        ret = wolfSSH_stream_read(ssh, buffer->data + buffer->idx,
                buffer->sz - buffer->idx);
        if (ret < 0) {
            return WS_FATAL_ERROR;
        }
        buffer->idx += (word32)ret;
    } while (buffer->idx < buffer->sz);

    return buffer->sz;
}
static int wolfSSH_SFTP_buffer_read(WOLFSSH* ssh, WS_SFTP_BUFFER* buffer,
        int readSz)
{
    int ret;

    if (buffer == NULL || ssh == NULL) {
        return WS_FATAL_ERROR;
    }

    if (readSz == 0) {
        return 0;
    }

    if (buffer->data == NULL) {
        buffer->idx = 0;
        buffer->sz  = readSz;
        buffer->data = (byte*)WMALLOC(buffer->sz, ssh->ctx->heap,
               DYNTYPE_BUFFER);
        if (buffer->data == NULL) {
            return WS_MEMORY_E;
        }
    }

    do {
        ret = wolfSSH_stream_read(ssh, buffer->data + buffer->idx,
                buffer->sz - buffer->idx);
        if (ret < 0) {
            return WS_FATAL_ERROR;
        }
        buffer->idx += (word32)ret;
    } while (buffer->idx < buffer->sz);

    return buffer->sz;
}