---
layout: default
menu_item: api
title: Odb
description: Version 0.26.1
menu_item: api
return_to:
"API Documentation Index": /api/
sections:
"hashfile": "#hashfile"
"open": "#open"
"#addDiskAlternate": "#addDiskAlternate"
"#existsPrefix": "#existsPrefix"
"#read": "#read"
"#readPrefix": "#readPrefix"
"#write": "#write"
"STREAM": "#STREAM"
---
## Odb.hashfile Async
```js
Odb.hashfile(path, type).then(function(oid) {
// Use oid
});
```
| Parameters | Type | |
| --- | --- | --- |
| path | String | file to read and determine object id for |
| type | Number | the type of the object that will be hashed |
| Returns | |
| --- | --- |
| [Oid](/api/oid/) | oid structure the result is written into. |
## Odb.open Async
```js
Odb.open(objects_dir).then(function(odb) {
// Use odb
});
```
| Parameters | Type | |
| --- | --- | --- |
| objects_dir | String | path of the backends' "objects" directory. |
| Returns | |
| --- | --- |
| [Odb](/api/odb/) | |
## Odb#addDiskAlternate Async
```js
odb.addDiskAlternate(path).then(function(result) {
// Use result
});
```
| Parameters | Type |
| --- | --- | --- |
| path | String | path to the objects folder for the alternate |
| Returns | |
| --- | --- |
| Number | 0 on success; error code otherwise |
## Odb#existsPrefix Async
```js
odb.existsPrefix(short_id, len).then(function(oid) {
// Use oid
});
```
| Parameters | Type |
| --- | --- | --- |
| short_id | [Oid](/api/oid/) | A prefix of the id of the object to read. |
| len | Number | The length of the prefix. |
| Returns | |
| --- | --- |
| [Oid](/api/oid/) | The full OID of the found object if just one is found. |
## Odb#read Async
```js
odb.read(id).then(function(odbObject) {
// Use odbObject
});
```
| Parameters | Type |
| --- | --- | --- |
| id | [Oid](/api/oid/) | identity of the object to read. |
| Returns | |
| --- | --- |
| [OdbObject](/api/odb_object/) | the read object |
## Odb#readPrefix Async
```js
odb.readPrefix(short_id, len).then(function(odbObject) {
// Use odbObject
});
```
| Parameters | Type |
| --- | --- | --- |
| short_id | [Oid](/api/oid/) | a prefix of the id of the object to read. |
| len | Number | the length of the prefix |
| Returns | |
| --- | --- |
| [OdbObject](/api/odb_object/) | the read object |
## Odb#write Async
```js
odb.write(data, len, type).then(function(oid) {
// Use oid
});
```
| Parameters | Type |
| --- | --- | --- |
| data | Buffer | buffer with the data to store |
| len | Number | size of the buffer |
| type | Number | type of the data to store |
| Returns | |
| --- | --- |
| [Oid](/api/oid/) | |
## Odb.STREAM ENUM
| Flag | Value |
| --- | --- | --- |
| Odb.STREAM.RDONLY | 2 |
| Odb.STREAM.WRONLY | 4 |
| Odb.STREAM.RW | 6 |