vibesketch.document.io¶
Read and write .vsk files.
A document is UTF-8 JSON, indented by two spaces, with a trailing newline,
so a .vsk diffs cleanly under version control. Writing is atomic: the
file is written beside its target and renamed over it, so an interrupted
save never leaves half a document.
Module Attributes
|
The file extension of a vibe-sketch document. |
What |
Functions
|
Refuse a protected QVF destination before an operation with side effects. |
|
The SHA-256 of a file's bytes, or |
|
The document as |
|
Validate already-parsed JSON data as a document, within |
|
Read and validate a document: a |
|
Parse and validate a document from JSON text, within |
|
An empty document stamped with this application and the current time. |
|
Write |
|
Readable |
|
|
|
Atomically write exported bytes, protecting existing QVF result files. |
Exceptions
|
A document that is not valid JSON or not a valid vibe-sketch document. |
Writing would discard QVF result data or replace a changed target. |
- vibesketch.document.io.ABSENT = 'absent'¶
What
digest_of()says of a file that does not exist.
- exception vibesketch.document.io.DocumentError(errors)[source]¶
Bases:
ValueErrorA document that is not valid JSON or not a valid vibe-sketch document.
errorslists every problem as"location: message", the form the CLI prints and the REST API returns.
- exception vibesketch.document.io.SaveRefused[source]¶
Bases:
ValueErrorWriting would discard QVF result data or replace a changed target.
- vibesketch.document.io.check_output(path)[source]¶
Refuse a protected QVF destination before an operation with side effects.
write_output()checks again at the actual write; this preflight is useful before submitting jobs whose run records must be saved in place.
- vibesketch.document.io.digest_of(path)[source]¶
The SHA-256 of a file’s bytes, or
ABSENTwhen there is no file.
- vibesketch.document.io.load(path)[source]¶
Read and validate a document: a
.qvfarchive or a.vskfile.
- vibesketch.document.io.loads(text)[source]¶
Parse and validate a document from JSON text, within
vibesketch.limits.
- vibesketch.document.io.new_document(app=None)[source]¶
An empty document stamped with this application and the current time.
- vibesketch.document.io.save(document, path, *, expect=None)[source]¶
Write
documenttopathatomically; returns the path written.A
.qvfpath gets a QVF archive (raisingQvfUnavailablewithout qvf-writer), any other a.vsk. A file that exists keeps its permissions; a new one gets the umask’s. QVF results and archives with data outside the native sketch raiseSaveRefused; save the sketch to another path instead. Withexpect(adigest_of()), a file that no longer holds those bytes is not replaced either.
- vibesketch.document.io.validation_errors(error)[source]¶
Readable
location: messagelines for a pydantic validation error.
- vibesketch.document.io.with_edit(document, *, actor, client, summary)[source]¶
documentwith an edit recorded for its next revision.A run of alike edits (same actor, client and summary) folds into one entry, so a drawing session does not leave hundreds. The revision itself is the caller’s to advance: the server’s store does it on commit.
- vibesketch.document.io.write_output(path, content, *, expect=None)[source]¶
Atomically write exported bytes, protecting existing QVF result files.
This also guards explicit format overrides (such as SVG sent to a QVF filename). Symlinks retain their link and write through to their target. With
expect, the file must still hold the bytes thatdigest_of()measured (or still be absent), before writing and again at the rename; otherwiseSaveRefused, and the file is left as it is.The new bytes reach the disk before they replace the old ones, and the directory entry after, so a crash or a full disk leaves either the old file or the new one, never a mixture. A crash at the wrong moment can leave a hidden
.NAME.*.tmpbeside it, which is safe to delete.