private function writeResource($file, $value, $indentation, $requireBraces = true)
    {
        if (\is_int($value)) {
            $this->writeInteger($file, $value);

            return;
        }

        if ($value instanceof \Traversable) {
            $value = iterator_to_array($value);
        }

        if (\is_array($value)) {
            $intValues = \count($value) === \count(array_filter($value, 'is_int'));

            $keys = array_keys($value);

            // check that the keys are 0-indexed and ascending
            $intKeys = $keys === range(0, \count($keys) - 1);

            if ($intValues && $intKeys) {
                $this->writeIntVector($file, $value, $indentation);

                return;
            }

            if ($intKeys) {
                $this->writeArray($file, $value, $indentation);

                return;
            }

            $this->writeTable($file, $value, $indentation);

            return;
        }

        if (\is_bool($value)) {
            $value = $value ? 'true' : 'false';
        }

        $this->writeString($file, (string) $value, $requireBraces);
    }