{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Write, read, and inspect a file\n", "\n", "Use an OpenDAL operator to store a file in a temporary local directory.\n", "\n", "Run `pip install opendal` in the environment that runs this notebook before executing the example." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from tempfile import TemporaryDirectory\n", "\n", "import opendal\n", "\n", "with TemporaryDirectory() as root:\n", " op = opendal.Operator(\"fs\", root=root)\n", " path = \"hello.txt\"\n", " message = b\"Hello, World!\"\n", " op.write(path, message)\n", "\n", " content = op.read(path)\n", " metadata = op.stat(path)\n", " assert content == message\n", " assert metadata.content_length == len(message)\n", " print(f\"{content.decode()} ({metadata.content_length} bytes)\")" ] } ], "metadata": { "language_info": { "name": "python" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }