How to use the aiofiles.os.stat function in aiofiles

To help you get started, we’ve selected a few aiofiles examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Tinche / aiofiles / tests / test_os.py View on Github external
contents = f.read()

    input_file = yield from aiofiles.open(filename)
    output_file = yield from aiofiles.open(str(tmp_filename), mode='w+')

    size = (yield from aiofiles.os.stat(filename)).st_size

    input_fd = input_file.fileno()
    output_fd = output_file.fileno()

    yield from aiofiles.os.sendfile(output_fd, input_fd, 0, size)

    yield from output_file.seek(0)

    actual_contents = yield from output_file.read()
    actual_size = (yield from aiofiles.os.stat(str(tmp_filename))).st_size

    assert contents == actual_contents
    assert size == actual_size
github huge-success / sanic / sanic / static.py View on Github external
for key, value in _range.headers.items():
                            headers[key] = value
            headers["Content-Type"] = (
                content_type or guess_type(file_path)[0] or "text/plain"
            )
            if request.method == "HEAD":
                return HTTPResponse(headers=headers)
            else:
                if stream_large_files:
                    if type(stream_large_files) == int:
                        threshold = stream_large_files
                    else:
                        threshold = 1024 * 1024

                    if not stats:
                        stats = await stat(file_path)
                    if stats.st_size >= threshold:
                        return await file_stream(
                            file_path, headers=headers, _range=_range
                        )
                return await file(file_path, headers=headers, _range=_range)
        except ContentRangeError:
            raise
        except Exception:
            raise FileNotFound(
                "File not found", path=file_or_directory, relative_url=file_uri
            )
github encode / starlette / starlette / staticfiles.py View on Github external
async def check_config(self) -> None:
        """
        Perform a one-off configuration check that StaticFiles is actually
        pointed at a directory, so that we can raise loud errors rather than
        just returning 404 responses.
        """
        if self.directory is None:
            return

        try:
            stat_result = await aio_stat(self.directory)
        except FileNotFoundError:
            raise RuntimeError(
                f"StaticFiles directory '{self.directory}' does not exist."
            )
        if not (stat.S_ISDIR(stat_result.st_mode) or stat.S_ISLNK(stat_result.st_mode)):
            raise RuntimeError(
                f"StaticFiles path '{self.directory}' is not a directory."
            )