# 设备即存储

Canonical URL: https://developers.iagenify.com/zh/sdk/concepts/machines-are-storages/
Language: zh

机器运行 SDK 第一次交换密钥时, 就会在您的账户上注册。 这正是让代理商工作的原因, 这也是为什么其文件从不离开机器的原因。

Status: registered on first call · files stay local

## 想法 {#idea}

存储是在数据生命的任何地方,而清单是故意混在一起的:计算机、浏览器、管理下的云存储、数据库或桶,与自己的证书相连。在字节的位置上,它们不同,在如何到达它们方面不同。

| 型 型 | 其数据系何地 | 联系 |
| --- | --- | --- |
| 计算机计算机 | 下,在 ~/.iagenify/files | storage.files |
| 电话电话 | 浏览器中的 | 连接您提供的文档 |
| IaGenify 云云 | 管理为您管理 | storage.run() |
| 连接数据库或桶 | 由您的提供者提供,您的全权证书 | storage.run() |

## 机器如何到达 {#registering}

您不注册它。 在第一个密钥交换 SDK 机器身份、 环境、 检测到的资源 以及机器出现在列表中。 之后, 保存相同的身份, 因为存储身份与会话缓存 。

```javascript
const pc = await api.storage.get();   // this machine

pc.id;
pc.type;        // "filesystem"
pc.hostname;
pc.isDefault;

await api.storage.list();             // every storage on the account
```

## 为什么电脑保存档案 {#local}

计算机存储服务器上没有计算机存储的字节,而且这是强制的,而不仅仅是意图:拒绝针对一个的上传 `storage_is_local`。在那里工作的代理人通过机器本身阅读和写作。

```javascript
// Refused — a computer is not a destination for an upload
await api.files.create({ name: "notes.md", content }).save({ localOnly: false });
// IaGenifyError: storage_is_local

// This is the way: the file is written on the machine
await pc.files.write("notes.md", content);
```

## 默认存储 {#default}

每个账户都有一个账户,它就是没有目的地的储蓄去的地方。 计算机违约情况很差,因为这个原因,它无法接收一个账户,所以默认通常指在管理下的云存储处。

```javascript
await api.getStorage();              // the default
await api.storage.remove(id);        // allowed even for the default
                                     // another storage inherits the flag
```

- [api.storage](/zh/sdk/ref/storage): 连接、列名、创建和删除。
- [文件桥](/zh/sdk/runtimes/browser): 给代理服务器文件操作 没有磁盘 。

```python
pc = api.storage.get()   # this machine

pc.id
pc.type          # "filesystem"
pc.machine_id
pc.is_default

api.storage.list()       # every storage on the account
```

```python
# Refused — a computer is not a destination for an upload
api.files.create(name="notes.md", content=content).save(local_only=False)
# IaGenifyError: storage_is_local

# This is the way: the file is written on the machine
pc.files.write("notes.md", content)
```

```python
api.get_storage()             # the default
api.storage.remove(storage_id)  # allowed even for the default:
                                # another storage inherits the flag
```
