Fs / read
TypeScript
Read from a file. Errors: - ESTALE - The inode does not exist. - EISDIR - The inode was a directory. - EINVAL - The inode was not a file suitable for reading.
Request parameters
{
/** The model's id. */
modelId: string,
/** If provided, the filesystem of the snapshot will be used. Otherwise, the filesystem of the model will be used. */
snapshotId?: string,
/** Inode number of file. */
inode: number,
/** Where in the file to start reading. */
offset: number,
/** Number of bytes to read. */
count: number
}
Response
{
/** If successful. One of "result" and "error" will be present. */
result?: {
data: Buffer
},
/** If failed */
error?: {
code: 'model_not_found' | 'snapshot_not_found' | 'ESTALE' | 'EISDIR' | 'EINVAL' | 'bad_credentials' | 'too_many_requests' | 'payment_required' | 'unknown'
} | {
code: 'invalid_parameter',
parameterName: string,
reason: string
}
}
Example
Following the installation guide to setup the Decthings API for TypeScript. Add your parameters to the following code and run it in Node.js, or in a browser by using a bundler.
The code reads your API key from file. Create an API key and save it to the file "auth.txt". Keep your key safe!
import * as fs from 'fs'
import { DecthingsClient } from '@decthings/api-client'
let apiKey = fs.readFileSync('./auth.txt').toString().trim()
let client = new DecthingsClient({ apiKey })
async function main() {
try {
let response = await client.fs.read({
modelId: /* Add modelId here */,
inode: /* Add inode here */,
offset: /* Add offset here */,
count: /* Add count here */
})
if (result.error) {
// Decthings sent us an error
console.log(response.error)
} else {
// Success!
console.log(response.result)
}
}
catch (e) {
// Client throws an error on connection issues. The function may or may not have succeded
console.log(e)
}
}
main()