Skip to content

lib-io 库参考 ​

原文: https://finproducts.atlassian.net/wiki/spaces/JIDD3/pages/34793554370/FIN+5.3.1+lib-io 中文整理基于 FIN 5.3.1

导读: 输入/输出函数库

以下为 API 参考,保留英文以便对照源码;目录已列出(英文标题便于检索);概述已尽量中译。


目录(导读) ​

  • lib
  • meta
  • docs
  • funcs
  • Overview
  • IO Handles
    • FTP Handles
  • Examples
  • ioAppend(handle)
  • ioCharset(handle, charset)
  • ioCopy(from, to, opts: {})
  • ioCrc(handle, algorithm)
  • ioCreate(handle)
  • ioDelete(handle)
  • ioDigest(handle, algorithm)
  • ioDir(handle)
  • ioEachCsv(handle, opts, fn)
  • ioEachLine(handle, fn)
  • ioExport(req, handle)
  • ioFromBase64(s)
  • ioGzip(handle)
  • ioHmac(handle, algorithm, key)
  • ioInfo(handle)
  • ioMove(from, to)
  • ioPbk(algorithm, password, salt, iterations, keyLen)
  • ioRandom(size)
  • ioReadCsv(handle, opts: null)
  • ioReadJson(handle, opts: null)
  • ioReadJsonGrid(handle, opts: null)
  • ioReadLines(handle, opts: null)
  • ioReadStr(handle)
  • ioReadTrio(handle)
  • ioReadXeto(handle, opts: null)
  • ioReadZinc(handle)
  • ioSkip(handle, opts)
  • ioStreamCsv(handle, opts: null)
  • ioStreamLines(handle)
  • ioToBase64(handle, opts: null)
  • ioToHex(handle)
  • ioWriteCsv(val, handle, opts: null)
  • ioWriteExcel(val, handle)
  • ioWriteHtml(val, handle, opts: {})
  • ioWriteJson(val, handle, opts: null)
  • ioWriteJsonLd(val, handle)
  • ioWriteLines(lines, handle)
  • ioWritePdf(val, handle, opts: {})
  • ioWriteStr(str, handle)
  • ioWriteSvg(val, handle, opts: {})
  • ioWriteTrio(val, handle, opts: null)
  • ioWriteTurtle(val, handle)
  • ioWriteXeto(val, handle, opts: null)
  • ioWriteXml(val, handle)
  • ioWriteZinc(val, handle)
  • ioZipDir(handle)
  • ioZipEntry(handle, path)

概述(中译) ​

输入/输出函数库


API 正文(英文) ​

docs ​

Overview • IO Handles • Examples


funcs ​

ioAppendConvert a handle to append mode
ioCharsetConfigure an I/O handle to use the specified charset
ioCopyCopy a file or directory to the new specified location
ioCrcGenerate a cycle reduancy check code as a Number
ioCreateCreate a directory or empty file with the given I/O handle
ioDeleteDelete a file or a directory as mapped by the given I/O handle
ioDigestGenerate a one-way hash of the given I/O handle
ioDirRead a directory listing, return a grid with cols
ioEachCsvIterate the rows of a CSV file (comma separated values) and callback the given function with two parameters
ioEachLineFor each line of the given source stream call the given function with two parameters
ioExportExport a view to the given file handle - see Export
ioFromBase64Return an I/O handle to decode from a base64 string
ioGzipWrap an I/O handle to GZIP compress/uncompress
ioHmacGenerate an HMAC message authentication as specified by RFC 2104
ioInfoGet information about a file handle and return a Dict with the same tags as ioDir()
ioMoveMove or rename a file or directory
ioPbkGenerate a password based cryptographic key
ioRandomGenerate randomized series of bytes which can be used as an input I/O handle
ioReadCsvRead a CSV (comma separated values) file into memory as a Grid
ioReadJsonRead a JSON file into memory
ioReadJsonGridRead a JSON file formatted as a standardized Haystack grid into memory
ioReadLinesRead an I/O handle into memory as a list of string lines
ioReadStrRead an I/O handle into memory as a string
ioReadTrioRead a Trio file into memory as a list of Dicts
ioReadXetoRead a Xeto data file into memory as a Haystack data type
ioReadZincRead a Zinc file into memory as a Haystack data type
ioSkipApply a skipping operation to an input I/O handle
ioStreamCsvRead a stream of dicts from a comma separated value file
ioStreamLinesRead a stream of lines
ioToBase64Encode an I/O handle into a base64 string
ioToHexEncode an I/O handle into hexidecimal string
ioWriteCsvWrite a grid to a CSV (comma separated values) file
ioWriteExcelWrite an Excel XLS file, where val may be
ioWriteHtmlWrite an Axon data structure to HTML
ioWriteJsonWrite an Axon data structure to JSON
ioWriteJsonLdWrite an Axon data structure to RDF JSON-LD format
ioWriteLinesWrite a list of string lines separated with "\n" character
ioWritePdfRender data to a PDF file
ioWriteStrWrite a string to an I/O handle
ioWriteSvgRender data to an SVG file
ioWriteTrioWrite dicts to a Trio file
ioWriteTurtleWrite an Axon data structure to RDF Turtle format
ioWriteXetoWrite value to a Xeto text format file
ioWriteXmlWrite a grid to an XML file
ioWriteZincWrite a Grid to the Zinc format
ioZipDirRead a zip file's entry listing, return a grid with cols
ioZipEntryReturn a I/O handle which may be used to read from a zip entry within a zip file

lib io ​

Overview ​

The ioExt is used to read/write data via a variety of formats:

  • Text strings: ioReadStr(), ioWriteStr()
  • Text lines: ioReadLines(), ioWriteLines()
  • Zinc: ioReadZinc(), ioWriteZinc()
  • Trio: ioReadTrio(), ioWriteTrio()
  • CSV: ioReadCsv(), ioWriteCsv(), ioEachCsv(), ioStreamCsv()
  • JSON: ioReadJson(), ioWriteJson()
  • XML: ioWriteXml(), xmlRead()
  • PDF: ioWritePdf()
  • SVG: ioWriteSvg()
  • HTML: ioWriteHtml()
  • RDF: ioWriteTurtle(), ioWriteJsonLd()

IO Handles ​

All the read/write functions take an IO handle which is one of the following:

  • any string can be used by the the read functions; if used for a write function then the output is concatenated to the end of the string and returned as the result of the write function
  • Uri which starts with "io/" which read/writes relative to the project's io directory
  • Uri with fan:// scheme will read files bundled in pods
  • Uri with http:// or https:// scheme will read using HTTP GET request (readonly)
  • Uri with ftp:// or ftps:// scheme will retreive using FTP
  • any Dict can be used as an IOHandle. Data will be stored in Folio keyed off the id of the rec. The data will be removed when the rec is deleted from folio.

The default charset used by all I/O handles is "UTF-8". You can wrap any of the handles above with the ioCharset() function to specify an alternate charset.

FTP Handles ​

You may read and write files to a FTP server via a ftp:// or ftps:// Uri. Using ioDir() is supported if Uri ends with a slash, but returns name only (not dir, size, or mod). By default the "anonymous" user account is used. But you can customize this by creating a key/value the password manager where the key is the base URI and the value is a string formatted as "user:pass". For example given:

uri:  ftp://somehost/somefile.csv
user: bob
pass: secret

You can setup the password for all FTP request to "ftp://somehost/" like this:

passwordSet("ftp://somehost/", "bob:secret")

Note that the URI key must end with a slash and match the scheme (ftp or ftps).

In newer versions of Java, you may see the following warning in the console the first time an FTPS connection is made:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by fan.ftp.FtpClientPeer (file:) to field sun.security.ssl.SSLSessionContextImpl.sessionHostPortCache
WARNING: Please consider reporting this to the maintainers of fan.ftp.FtpClientPeer
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

If you see this, then you need to edit your etc/sys/config.props and add the following options to the java.options along with any other options you have set (e.g. heap configuration).

java.options=--add-opens java.base/sun.security.ssl=ALL-UNNAMED --add-opens java.base/sun.security.util=ALL-UNNAMED

Examples ​

Here are some basic examples:

// export your sites to a trio file: {proj}/io/sites.trio
readAll(site).ioWriteTrio(`io/sites.trio`)

// export your sites to a trio string literal
readAll(site).ioWriteTrio("")

// export point to CSV file
read(weatherTemp).hisRead(pastMonth).ioWriteCsv(`io/point.csv`)

// import history data from CSV file where timestamps
// are formatted as 2010-10-02T13:00
ioReadCsv(`io/his.csv`)
  .map(row => {ts: parseDateTime(row->ts, "YYYY-MM-DD'T'hh:mm", "New_York"),
               val: parseNumber(row->val)})
  .hisWrite(hisId)

// parse an oBIX XML document and map into name/value pairs
xmlRead(`http://obix.acme.com/obix/about`).xmlElems
  .map(x => {name:x.xmlAttr("name").xmlVal, val:x.xmlAttr("val").xmlVal})


def ​

func:ioAppend ​

ioAppend(handle) ​

Convert a handle to append mode. Writes will append to the end of the file instead of rewriting the file. Raises UnsupportedErr if the handle doesn't support append mode.

Example:

ioWriteStr("append a line\n", ioAppend(`io/foo.txt`))

meta ​

admin✓
deffunc:ioAppend
isfunc
liblib:io
nameioAppend

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioCharset ​

ioCharset(handle, charset) ​

Configure an I/O handle to use the specified charset. The handle is any supported I/O handle and the charset is a string name supported by the JVM installation. Standard charset names:

  • "UTF-8" 8-bit Unicode Transformation Format
  • "UTF-16BE": 16 bit Big Endian Unicode Transformation Format
  • "UTF-16LE" 16 bit Little Endian Unicode Transformation Format
  • "ISO-8859-1": Latin-1 code block
  • "US-ASCII": 7-bit ASCII

Examples:

// write text file in UTF-16BE
ioWriteStr(str, ioCharset(`io/foo.txt`, "UTF-16BE"))

// read CSV file in ISO-8859-1
ioCharset(`io/foo.csv`, "ISO-8859-1").ioReadCsv

meta ​

admin✓
deffunc:ioCharset
isfunc
liblib:io
nameioCharset

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioCopy ​

ioCopy(from, to, opts: {}) ​

Copy a file or directory to the new specified location. If this file represents a directory, then it recursively copies the entire directory tree. Both handles must reference a local file or directory on the file system.

If during the copy, an existing file of the same name is found, then the "overwrite" option should be to marker or true to overwrite or false to skip. Or if overwrite is not defined then an IOErr is raised.

Examples:

ioCopy(`io/dir/`, `io/dir-copy/`)
ioCopy(`io/file.txt`, `io/file-copy.txt`)
ioCopy(`io/file.txt`, `io/file-copy.txt`, {overwrite})
ioCopy(`io/file.txt`, `io/file-copy.txt`, {overwrite:false})

meta ​

admin✓
deffunc:ioCopy
isfunc
liblib:io
nameioCopy

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioCrc ​

ioCrc(handle, algorithm) ​

Generate a cycle reduancy check code as a Number. See Buf.crc for available algorithms.

Example:

ioCrc("foo", "CRC-32").toHex

meta ​

admin✓
deffunc:ioCrc
isfunc
liblib:io
nameioCrc

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioCreate ​

ioCreate(handle) ​

Create a directory or empty file with the given I/O handle. If creating a file that already exists, it is overwritten as empty.

Examples:

ioCreate(`io/new-dir/`)        // create new empty directory
ioCreate(`io/new-file.txt`)    // create new empty file

meta ​

admin✓
deffunc:ioCreate
isfunc
liblib:io
nameioCreate

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioDelete ​

ioDelete(handle) ​

Delete a file or a directory as mapped by the given I/O handle. If a directory is specified, then it is recursively deleted. If the I/O handle does map to a file system then raise exception. If the file does not exist then no action is taken.


meta ​

admin✓
deffunc:ioDelete
isfunc
liblib:io
nameioDelete

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioDigest ​

ioDigest(handle, algorithm) ​

Generate a one-way hash of the given I/O handle. See Buf.toDigest for available algorithms.

Example:

ioDigest("foo", "SHA-1").ioToBase64

meta ​

admin✓
deffunc:ioDigest
isfunc
liblib:io
nameioDigest

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioDir ​

ioDir(handle) ​

Read a directory listing, return a grid with cols:

  • uri: Uri for handle to read/write the file
  • name: filename string
  • mimeType: file mime type or null if unknown
  • dir: marker if file is a sub-directory or null
  • size: size of file in bytes or null
  • mod: modified timestamp or null if unknown

If the I/O handle does not map to a file in the virtual file system then throw an exception.

ioDir(`io/`)             // read files in project's io/ directory
ioDir(`fan://haystack`)  // read files in pod

meta ​

admin✓
deffunc:ioDir
isfunc
liblib:io
nameioDir

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioEachCsv ​

ioEachCsv(handle, opts, fn) ​

Iterate the rows of a CSV file (comma separated values) and callback the given function with two parameters: Str[] cells of current row and zero based Number line number.

The following options are supported:

  • delimiter: separator char as string, default is ","

Also ioReadCsv(), ioWriteCsv(), and CSV.


meta ​

admin✓
deffunc:ioEachCsv
isfunc
liblib:io
nameioEachCsv

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioEachLine ​

ioEachLine(handle, fn) ​

For each line of the given source stream call the given function with two parameters: Str line and zero based Number line number. Lines are processed according to InStream.eachLine.


meta ​

admin✓
deffunc:ioEachLine
isfunc
liblib:io
nameioEachLine

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioExport ​

ioExport(req, handle) ​

Export a view to the given file handle - see Export.

Note: this feature is available in SkySpark only


meta ​

admin✓
deffunc:ioExport
isfunc
liblib:io
nameioExport

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioFromBase64 ​

ioFromBase64(s) ​

Return an I/O handle to decode from a base64 string. Also see ioToBase64() and Buf.fromBase64

Example:

// decode base64 to a string
ioFromBase64("c2t5c3Bhcms").ioReadStr

meta ​

admin✓
deffunc:ioFromBase64
isfunc
liblib:io
nameioFromBase64

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioGzip ​

ioGzip(handle) ​

Wrap an I/O handle to GZIP compress/uncompress.

Example:

// generate GZIP CSV file
readAll(site).ioWriteCsv(ioGzip(`io/sites.gz`))

// read GZIP CSV file
ioGzip(`io/sites.gz`).ioReadCsv

meta ​

admin✓
deffunc:ioGzip
isfunc
liblib:io
nameioGzip

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioHmac ​

ioHmac(handle, algorithm, key) ​

Generate an HMAC message authentication as specified by RFC 2104. See Buf.hmac.

Example:

ioHmac("foo", "SHA-1", "secret").ioToBase64

meta ​

admin✓
deffunc:ioHmac
isfunc
liblib:io
nameioHmac

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioInfo ​

ioInfo(handle) ​

Get information about a file handle and return a Dict with the same tags as ioDir().

If the I/O handle does not map to a file in the virtual file system then throw an exception.

ioInfo(`io/`)            // read file info for the project's io/ directory
ioInfo(`io/sites.trio`)  // read file info for the io/sites.trio file

meta ​

admin✓
deffunc:ioInfo
isfunc
liblib:io
nameioInfo

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioMove ​

ioMove(from, to) ​

Move or rename a file or directory. Both handles must reference a local file or directory on the file system. If the target file already exists then raise an IOErr.


meta ​

admin✓
deffunc:ioMove
isfunc
liblib:io
nameioMove

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioPbk ​

ioPbk(algorithm, password, salt, iterations, keyLen) ​

Generate a password based cryptographic key. See Buf.pbk.

Example:

ioPbk("PBKDF2WithHmacSHA1", "secret", ioRandom(64), 1000, 20).ioToBase64

meta ​

admin✓
deffunc:ioPbk
isfunc
liblib:io
nameioPbk

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioRandom ​

ioRandom(size) ​

Generate randomized series of bytes which can be used as an input I/O handle.


meta ​

admin✓
deffunc:ioRandom
isfunc
liblib:io
nameioRandom

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioReadCsv ​

ioReadCsv(handle, opts: null) ​

Read a CSV (comma separated values) file into memory as a Grid. CSV format is implemented as specified by RFC 4180:

  • rows are delimited by a newline
  • cells are separated by delimiter char
  • cells containing the delimiter, " double quote, or newline are quoted; quotes are escaped as ""
  • empty cells are normalized into null

The following options are supported:

  • delimiter: separator char as string, default is ","
  • noHeader: if present then don't treat first row as col names, instead use "v0", "v1", etc

Also see ioStreamCsv(), ioEachCsv(), ioWriteCsv(), and CSV.


meta ​

admin✓
deffunc:ioReadCsv
isfunc
liblib:io
nameioReadCsv

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioReadJson ​

ioReadJson(handle, opts: null) ​

Read a JSON file into memory. This function can used to read any arbitrary JSON nested object/array structure which can be accessed as Axon dicts/lists. The default decoding assumes Haystack 4 JSON format (Hayson). Also see ioReadJsonGrid() if reading a Haystack formatted grid.

Object keys which are not valid tag names will decode correctly and can be used in-process. But they will not serialize correctly over the HTTP API. You can use the safeNames option to force object keys to be safe tag names (but you will lose the original key names).

The following options are supported:

  • v3: decode the JSON as Haystack 3
  • v4: explicitly request Haystack 4 decoding (default)
  • safeNames: convert object keys to safe tag names

meta ​

admin✓
deffunc:ioReadJson
isfunc
liblib:io
nameioReadJson

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioReadJsonGrid ​

ioReadJsonGrid(handle, opts: null) ​

Read a JSON file formatted as a standardized Haystack grid into memory. See ioReadJson() to read arbitrary JSON structured data.


meta ​

admin✓
deffunc:ioReadJsonGrid
isfunc
liblib:io
nameioReadJsonGrid

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioReadLines ​

ioReadLines(handle, opts: null) ​

Read an I/O handle into memory as a list of string lines. Lines are processed according to InStream.readLine semanatics.

By default the maximum line size read is 4kb of Unicode characters (not bytes). This limit may be overridden using the option key "limit".

Examples:

ioReadLines(`io/file.txt`)
ioReadLines(`io/file.txt`, {limit: 10_000})

meta ​

admin✓
deffunc:ioReadLines
isfunc
liblib:io
nameioReadLines

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioReadStr ​

ioReadStr(handle) ​

Read an I/O handle into memory as a string. Newlines are always normalized into "\n" characters.


meta ​

admin✓
deffunc:ioReadStr
isfunc
liblib:io
nameioReadStr

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioReadTrio ​

ioReadTrio(handle) ​

Read a Trio file into memory as a list of Dicts.


meta ​

admin✓
deffunc:ioReadTrio
isfunc
liblib:io
nameioReadTrio

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioReadXeto ​

ioReadXeto(handle, opts: null) ​

Read a Xeto data file into memory as a Haystack data type. See LibNamespace.compileData for details and options.


meta ​

admin✓
deffunc:ioReadXeto
isfunc
liblib:io
nameioReadXeto

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioReadZinc ​

ioReadZinc(handle) ​

Read a Zinc file into memory as a Haystack data type.


meta ​

admin✓
deffunc:ioReadZinc
isfunc
liblib:io
nameioReadZinc

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioSkip ​

ioSkip(handle, opts) ​

Apply a skipping operation to an input I/O handle. The following options are available (in order of processing):

  • bom: skip byte order mark
  • bytes: number of bytes to skip (must be binary input stream)
  • chars: number of chars to skip (must be text input stream)
  • lines: number of lines to skip

Skipping a BOM will automatically set the appropiate charset. If no BOM is detected, then this call is safely ignored by pushing those bytes back into the input stream. The following byte order marks are supported:

  • UTF-16 Big Endian: 0xFE_FF
  • UTF-16 Little Endian: 0xFF_FE
  • UTF-8: 0xEF_BB_BF

Examples:

// skip leading 4 lines in a CSV file
ioSkip(`io/foo.csv`, {lines:4}).ioReadCsv

// skip byte order mark
ioSkip(`io/foo.csv`, {bom}).ioReadCsv

meta ​

admin✓
deffunc:ioSkip
isfunc
liblib:io
nameioSkip

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioStreamCsv ​

ioStreamCsv(handle, opts: null) ​

Read a stream of dicts from a comma separated value file. This function uses the same options and semantics as ioReadCsv() except it streams the rows as dicts instead of reading to an in-memory grid. See Streams.


meta ​

admin✓
deffunc:ioStreamCsv
isfunc
liblib:io
nameioStreamCsv

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioStreamLines ​

ioStreamLines(handle) ​

Read a stream of lines. Lines are processed according to InStream.eachLine. See Streams.


meta ​

admin✓
deffunc:ioStreamLines
isfunc
liblib:io
nameioStreamLines

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioToBase64 ​

ioToBase64(handle, opts: null) ​

Encode an I/O handle into a base64 string. The default behavior is to encode using RFC 2045 (see Buf.toBase64). Use the {uri} option to encode a URI-safe URI via RFC 4648 (see Buf.toBase64Uri). Also see ioFromBase64().

Example:

// encode string to base64
ioToBase64("myusername:mysecret")

// encode string to base64 without padding using URI safe chars
ioToBase64("myusername:mysecret", {uri})

meta ​

admin✓
deffunc:ioToBase64
isfunc
liblib:io
nameioToBase64

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioToHex ​

ioToHex(handle) ​

Encode an I/O handle into hexidecimal string.


meta ​

admin✓
deffunc:ioToHex
isfunc
liblib:io
nameioToHex

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioWriteCsv ​

ioWriteCsv(val, handle, opts: null) ​

Write a grid to a CSV (comma separated values) file.

CSV format is implemented as specified by RFC 4180:

  • rows are delimited by a newline
  • cells are separated by delimiter char
  • cells containing the delimiter, " double quote, or newline are quoted; quotes are escaped as ""

The following options are supported:

  • delimiter: separator char as string, default is ","
  • newline: newline string, default is "\n" (use "\r\n" for CRLF)
  • noHeader: Set this option to prevent the column names from being written as a header row.
  • stripUnits: write all numbers without a unit

Also ioReadCsv(), ioEachCsv(), and CSV.


meta ​

admin✓
deffunc:ioWriteCsv
isfunc
liblib:io
nameioWriteCsv

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioWriteExcel ​

ioWriteExcel(val, handle) ​

Write an Excel XLS file, where val may be:

  • Grid - writted a a single worksheet
  • Grid[] - each grid is exported as a separate worksheet

By default each worksheet is named "Sheet1", "Sheet2", etc. Use a title tag in Grid.meta to give the worksheets a specific name.

Example:

readAll(site).ioWriteExcel(`io/sites.xls`)

meta ​

admin✓
deffunc:ioWriteExcel
isfunc
liblib:io
nameioWriteExcel

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioWriteHtml ​

ioWriteHtml(val, handle, opts: {}) ​

Write an Axon data structure to HTML. The val must be an Axon type that can be converted to a Grid.


meta ​

admin✓
deffunc:ioWriteHtml
isfunc
liblib:io
nameioWriteHtml

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioWriteJson ​

ioWriteJson(val, handle, opts: null) ​

Write an Axon data structure to JSON. By default, Haystack 4 (Hayson) encoding is used. The val may be:

  • One of the SkySpark types that can be mapped to JSON. See Json for type mapping.

The following options are supported:

  • noEscapeUnicode: do not escape characters over 0x7F
  • v3: Encode JSON using Haystack 3 encoding
  • v4: Explicitly encode with Haystack 4 encoding (default)

meta ​

admin✓
deffunc:ioWriteJson
isfunc
liblib:io
nameioWriteJson

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioWriteJsonLd ​

ioWriteJsonLd(val, handle) ​

Write an Axon data structure to RDF JSON-LD format. The val must be an Axon type that can be converted to a Grid.


meta ​

admin✓
deffunc:ioWriteJsonLd
isfunc
liblib:io
nameioWriteJsonLd

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioWriteLines ​

ioWriteLines(lines, handle) ​

Write a list of string lines separated with "\n" character.


meta ​

admin✓
deffunc:ioWriteLines
isfunc
liblib:io
nameioWriteLines

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioWritePdf ​

ioWritePdf(val, handle, opts: {}) ​

Render data to a PDF file. The grid meta "view" tag determines the visualization:

  • table: render grid as table (default)
  • chart: render grid as chart
  • fandoc: render string as fandoc
  • text: render as plaintext

Options:

  • pageSize: determines the PDF page size

Examples:

// render as chart with default page size
read(power).hisRead(yesterday).ioWritePdf(`io/portrait.pdf`)

// render as chart with landscape page size of 11" x 8.5"
read(power).hisRead(yesterday).ioWritePdf(`io/landscape.pdf`, {pageSize:"11in,8.5in"})

// render table as single auto-fit page
readAll(site).ioWritePdf(`io/sites.pdf`, {pageSize:"auto"})

Note: this feature is available in SkySpark only


meta ​

admin✓
deffunc:ioWritePdf
isfunc
liblib:io
nameioWritePdf

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioWriteStr ​

ioWriteStr(str, handle) ​

Write a string to an I/O handle.


meta ​

admin✓
deffunc:ioWriteStr
isfunc
liblib:io
nameioWriteStr

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioWriteSvg ​

ioWriteSvg(val, handle, opts: {}) ​

Render data to an SVG file. Pass size option to specify the SVG viewBox, width, and height attribtues (defaults to "1000,800"). The visualization is determined by the grid meta "view" tag - see ioWritePdf() for specifics.

Examples:

read(power).hisRead(yesterday).ioWriteSvg(`io/example.svg`)

read(power).hisRead(yesterday).ioWriteSvg(`io/example.svg`, {size:"600,400"})

Note: this feature is available in SkySpark only


meta ​

admin✓
deffunc:ioWriteSvg
isfunc
liblib:io
nameioWriteSvg

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioWriteTrio ​

ioWriteTrio(val, handle, opts: null) ​

Write dicts to a Trio file. The val may be can be any format accepted by toRecList().

Following options are supported

  • noSort: marker to prevent tags from being sorted by name

meta ​

admin✓
deffunc:ioWriteTrio
isfunc
liblib:io
nameioWriteTrio

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioWriteTurtle ​

ioWriteTurtle(val, handle) ​

Write an Axon data structure to RDF Turtle format. The val must be an Axon type that can be converted to a Grid.


meta ​

admin✓
deffunc:ioWriteTurtle
isfunc
liblib:io
nameioWriteTurtle

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioWriteXeto ​

ioWriteXeto(val, handle, opts: null) ​

Write value to a Xeto text format file. See LibNamespace.writeData for details and options.


meta ​

admin✓
deffunc:ioWriteXeto
isfunc
liblib:io
nameioWriteXeto

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioWriteXml ​

ioWriteXml(val, handle) ​

Write a grid to an XML file.


meta ​

admin✓
deffunc:ioWriteXml
isfunc
liblib:io
nameioWriteXml

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioWriteZinc ​

ioWriteZinc(val, handle) ​

Write a Grid to the Zinc format.


meta ​

admin✓
deffunc:ioWriteZinc
isfunc
liblib:io
nameioWriteZinc

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioZipDir ​

ioZipDir(handle) ​

Read a zip file's entry listing, return a grid with cols:

  • path: path of entry inside zip as Uri
  • size: size of file in bytes or null
  • mod: modified timestamp or null if unknown

The handle must reference a zip file in the file system. Use ioZipEntry() to perform a read operation on one of the entries in the zip file.

Example:

ioZipDir(`io/batch.zip`)

meta ​

admin✓
deffunc:ioZipDir
isfunc
liblib:io
nameioZipDir

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:ioZipEntry ​

ioZipEntry(handle, path) ​

Return a I/O handle which may be used to read from a zip entry within a zip file. The handle parameter must be an I/O handle which references a zip file in the file system. The path parameter must be a Uri which identifies the path of the entry within the zip file. See ioZipDir() to read the listing of paths within a zip.

Example:

// read CSV file from within a zip
ioZipEntry(`io/batch.zip`, `/zone-temp.csv`).ioReadCsv

meta ​

admin✓
deffunc:ioZipEntry
isfunc
liblib:io
nameioZipEntry

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function