public function addResource($name, $resource, array $options = [])
    {
        $stream = $this->streamFactory->createStream($resource);

        // validate options['headers'] exists
        if (!isset($options['headers'])) {
            $options['headers'] = [];
        }

        // Try to add filename if it is missing
        if (empty($options['filename'])) {
            $options['filename'] = null;
            $uri = $stream->getMetadata('uri');
            if ('php://' !== substr($uri, 0, 6)) {
                $options['filename'] = $uri;
            }
        }

        $this->prepareHeaders($name, $stream, $options['filename'], $options['headers']);
        $this->data[] = ['contents' => $stream, 'headers' => $options['headers'], 'filename' => $options['filename']];

        return $this;
    }