open#
- barecat.io.open.open_(path, mode, *args, **kwargs)[source]#
Open a file, supporting ‘ax’ modes which Python’s builtin open() cannot do.
‘ax’ variants = exclusive create + append (+ optional read, binary): - ‘x’ = fail if file exists (O_EXCL) - ‘a’ = kernel-enforced append: ALL writes go to end regardless of seek position - ‘+’ = read+write (O_RDWR) instead of write-only (O_WRONLY) - ‘b’ = binary mode
WHY THE ‘a’ MATTERS: O_APPEND is enforced by the kernel, not Python. Even if code does seek(0) then write(), the kernel intercepts the syscall and redirects the write to EOF. This is OS-level protection against data corruption from seek bugs.
This is how barecat’s append_only mode is enforced at the file level: - append_only=True -> shard_mode_new = ‘ax+b’ (kernel enforces writes go to end) - append_only=False -> shard_mode_new = ‘x+b’ (allows seek+overwrite for defrag)
DO NOT “simplify” to ‘x’ modes - the ‘a’ provides kernel-level safety guarantees.