Something like this may help:
const fs = require("fs");
const arrow = require("apache-arrow");
const path = "data.arrow";
const tbl = arrow.tableFromArrays({data: new Int32Array([1, 2, 3])});
const data = arrow.tableToIPC(tbl, path);
fs.writeFileSync(path, data, "binary”);
The documentation has an example on how to read from IPC if you are interested
in roundtripping
https://arrow.apache.org/docs/js/#get-a-table-from-an-arrow-file-on-disk-in-ipc-format
<https://arrow.apache.org/docs/js/#get-a-table-from-an-arrow-file-on-disk-in-ipc-format>
> On Jun 8, 2022, at 10:08 AM, Howard Engelhart <[email protected]>
> wrote:
>
> Hi Philip,
>
> The way I did this was through the table...
>
> export function encodeTable(table:Table):DataBlock {
> let schema, records;
> let w = new RecordBatchStreamWriter();
> w.reset(undefined, table.schema);
> schema = Buffer.from(w.toUint8Array(true)).toString('base64');
> w = new RecordBatchStreamWriter();
> w.write(table);
> records =
> Buffer.from(w.toUint8Array(true)).toString('base64').replace(schema,'');
> return {
> aId: uuidv4(),
> schema,
> records
> };
> }
>
> Note, the DataBlock being returned here and separation of the records and the
> schema was specific to my application which was working with AWS Athena. You
> may not need this for your own. Also, if you're looking at writing to a
> file, take a look at replacing my use of RecordBatchStreamWriter with
> RecordBatchFileWriter.
>
> As far as creating the Table goes, there are a few different arrow helper
> functions for that.
>
> -H
>
>
>
> On Wed, Jun 8, 2022 at 12:30 PM Philip Zeyliger <[email protected]
> <mailto:[email protected]>> wrote:
> Hi!
>
> I'm trying to write an Arrow file from JS, and having trouble finding
> examples of writing (not reading) in the documentation/cookbooks. Pointers to
> examples would be appreciated!
>
> Thanks!
>
> -- Philip