Skip to content
@deckyard/escl

escl cheatsheet

Every export of @deckyard/escl. The guide is Scanning.

jennifer
import "@deckyard/escl/" as escl;

Lengths are in 1/300 inch. Every error the deck raises is kind "escl"; a scanEach handler's own error keeps its kind (a failed cancel is added to its message). Text from a scanner comes back with control, bidirectional-text and invisible format characters as ?. A login belongs in Options; an address holding @ is refused.

Scanners

FunctionReturnsDoes
escl.discover(timeoutMs as int)list of Foundscanners answering an mDNS query for _uscan._tcp / _uscans._tcp within timeoutMs (1 to 60000); names with control characters as ?; stops reading after 2000 records
escl.scanner(address as string)Scannerthe scanner at host, host:port or an http(s):// URL, default options; the eSCL root defaults to /eSCL
escl.scannerWith(address as string, options as Options)Scannerthe same, with options; zero fields take the defaults
escl.capabilities(s as Scanner)CapabilitiesGET ScannerCapabilities
escl.status(s as Scanner)StatusGET ScannerStatus
escl.parseCapabilities(text as string)Capabilitiesparse a saved ScannerCapabilities document
escl.parseStatus(text as string)Statusparse a saved ScannerStatus document

Settings

FunctionReturnsDoes
escl.settings()Settingsthe defaults: platen, RGB24, 300 dpi, image/jpeg, the whole area, no intent
escl.check(caps as Capabilities, st as Settings)Settingscheck every setting against the selected input; fills in a 0 width / height
escl.settingsXml(caps as Capabilities, st as Settings)stringthe ScanSettings document a job sends, after check
escl.fromMm(mm as float)intmillimetres (0 to 10000) to 1/300 inch, rounded

Jobs

FunctionReturnsDoes
escl.scanEach(s as Scanner, st as Settings, handler as func)intthe whole job, calling handler(page as Page, n as int) per page instead of keeping it; returns the page count
escl.scan(s as Scanner, st as Settings)list of Pagethe whole job, in memory; cancels it on failure; no pages, more than maxPages / maxJobBytes or an aborted job is an error; a finished job is deleted on the scanner
escl.scanToFiles(s as Scanner, st as Settings, dir as string, stem as string)list of stringthe whole job into <dir>/<stem>-001.<ext>, ... (more digits when maxPages needs them), the extension from the page's type or, failing that, its first bytes; files are created exclusively, never overwritten or written through a link; an error names the files already written
escl.start(s as Scanner, caps as Capabilities, st as Settings)Jobcheck the settings and create a job; a feeder job is refused when the feeder reports empty, jammed, open or misfed
escl.nextPage(job as Job)Pagethe next page, or done at the end (404); a platen job is done after one counted page, without asking again
escl.countPage(job as Job, p as Page)Jobthe job with the page counted, for a loop of your own; past maxPages or maxJobBytes is an error
escl.finish(job as Job)nullafter the last page: fails if the status lists the job aborted or cancelled, or it gave no pages (an unreadable status does not fail it), then deletes the job on the scanner
escl.cancel(job as Job)nulldelete the job; one the scanner no longer knows counts as cancelled
escl.imageInfo(job as Job)ImageInfoScanImageInfo of the page last fetched, where the scanner offers it
escl.extension(contentType as string)stringjpg, png, pdf, tif, else bin
escl.pageExtension(p as Page)stringthe extension from the page's type or, failing that, its first bytes

PDF

jennifer
import "@deckyard/escl/scanpdf.j" as scanpdf;
FunctionReturnsDoes
scanpdf.build(pages as list of escl.Page, resolution as int)bytesone PDF of JPEG / PNG pages, each page the size scanned at resolution dpi; images embedded unchanged; PNGs with transparency or interlacing refused
scanpdf.scanToPdf(s as escl.Scanner, st as escl.Settings, path as string)intscan (format image/jpeg or image/png) and write one PDF, created exclusively; the name is taken before the scan, and the pages of a failed job, or pages that cannot be bound or written, are kept as <path without .pdf>-001.<ext>, ... (-2-001, ... when taken); peak memory about seven times the job's size; returns the page count

Constants

ConstantValueMeaning
escl.PLATEN"Platen"the flatbed glass
escl.ADJUSTMENTS["Threshold", "Sharpen", "Contrast", "Brightness"]the image adjustments, in the order a request sends them
escl.FEEDER"Feeder"the automatic document feeder
escl.DEFAULT_TIMEOUT_MS120000how long one read may stall
escl.DEFAULT_BUSY_WAIT_MS60000how long a 503 is retried
escl.DEFAULT_RETRY_MS1000the pause between retries
escl.DEFAULT_MAX_PAGE_BYTES268435456the largest page accepted (256 MiB)
escl.DEFAULT_MAX_PAGES500the most pages one job may give
escl.DEFAULT_MAX_JOB_BYTES1073741824the most bytes one job may give (1 GiB)

Types

Options

FieldMeaning
skipVerify as boolaccept any HTTPS certificate
caCert as bytesa PEM certificate to trust for HTTPS
timeoutMs as inthow long one read may stall (0 = DEFAULT_TIMEOUT_MS)
busyWaitMs as inthow long to retry a 503 (0 = DEFAULT_BUSY_WAIT_MS)
retryMs as intthe pause between retries (0 = DEFAULT_RETRY_MS)
maxPageBytes as intthe largest page accepted (0 = DEFAULT_MAX_PAGE_BYTES)
maxJobBytes as intthe most bytes one job's pages may add up to (0 = DEFAULT_MAX_JOB_BYTES)
deadlineMs as intthe longest one request may take as a whole (0 = no limit beyond timeoutMs per read)
maxPages as intthe most pages one job may give in any whole-job call (0 = DEFAULT_MAX_PAGES)
username as stringan HTTP Basic login, "" for none
password as stringits password
allowPlainAuth as boolallow the login over plain http or with skipVerify; otherwise a login needs https with a verified (or caCert-pinned) certificate

Scanner

FieldMeaning
origin as stringscheme://host[:port]
base as stringthe eSCL root URL
options as Optionsthe options, defaults filled in

Capabilities

FieldMeaning
version as stringthe eSCL version
makeAndModel as stringthe device's name
serialNumber as string"" if not given
uuid as string"" if not given
adminUri as stringthe device's web page, "" if not given
iconUri as string"" if not given
inputs as list of Inputthe platen, the feeder, the duplex feeder
feederOptions as list of stringAdfOptions, e.g. DetectPaperLoaded, Duplex
formatExt as boolthe device lists DocumentFormatExt
adjustments as map of string to Adjustmentthe adjustments offered, keyed by a name in ADJUSTMENTS

Input

FieldMeaning
source as stringPLATEN or FEEDER
duplex as boolthe feeder's two-sided capabilities
minWidth as int1/300 inch
maxWidth as int1/300 inch
minHeight as int1/300 inch
maxHeight as int1/300 inch
colorModes as list of stringe.g. BlackAndWhite1, Grayscale8, RGB24
formats as list of stringMIME types
resolutions as list of intdiscrete dpi with X = Y, ascending
resolutionRanges as list of Rangethe continuous ranges, one per setting profile listing one
intents as list of stringe.g. Document, Photo

Adjustment

FieldMeaning
min as intthe lowest value
max as intthe highest value
normal as intthe scanner's default
step as intthe step from min

Found

FieldMeaning
name as stringthe announced name
host as stringthe mDNS host name
address as stringthe IPv4 address, "" if not in the answer
port as intthe eSCL port
secure as boolannounced as _uscans (HTTPS)
root as stringthe eSCL root, from TXT rs
model as stringTXT ty
uuid as stringTXT UUID
url as stringthe address to give escl.scanner

ImageInfo

FieldMeaning
width as intpixels
height as intpixels
bytesPerLine as intbytes per row, 0 if not given

Range

FieldMeaning
min as intthe lowest dpi; 0 when there is no range
max as intthe highest dpi
step as intthe step from min

Status

FieldMeaning
version as stringthe eSCL version
state as stringIdle, Processing, Testing, Stopped, Down
adfState as stringe.g. ScannerAdfLoaded, ScannerAdfEmpty, ScannerAdfJam; "" if not given
jobs as list of JobInfothe jobs the scanner remembers

JobInfo

FieldMeaning
uri as stringthe job's path
uuid as string"" if not given
age as intseconds since its last change
imagesCompleted as intpages scanned
imagesToTransfer as intpages not yet fetched
state as stringPending, Processing, Completed, Canceled, Aborted
reasons as list of stringe.g. JobCompletedSuccessfully

Settings

FieldMeaning
source as stringPLATEN or FEEDER
duplex as boolboth sides (the feeder only)
colorMode as stringone of the input's colorModes
resolution as intdpi, X and Y
format as stringone of the input's formats
intent as stringone of the input's intents, "" for none
x as intleft edge
y as inttop edge
width as int0 = to the maximum
height as int0 = to the maximum
adjust as map of string to intadjustments to send, keyed by a name in ADJUSTMENTS; unset ones keep the scanner's default

Job

FieldMeaning
scanner as Scannerthe scanner
url as stringthe job's absolute URL
pages as intpages fetched, as scan counts them
bytes as intthe bytes those pages hold
platen as boola platen job: nextPage ends it after one counted page

Page

FieldMeaning
done as boolno more pages; the other fields are empty
contentType as stringthe page's MIME type
data as bytesthe page as sent