This should be part of a more generic API, or we could possibly use the buffer api we have