[![npm version][npm-img]][npm-url]

[npm-img]: https://img.shields.io/npm/v/lerc.svg?style=flat-square
[npm-url]: https://www.npmjs.com/package/lerc

# Lerc JS

> Rapid decoding of Lerc compressed raster data for any standard pixel type, not just rgb or byte

## Browser

```html
<script type="text/javascript" src="./LercDecode.js"></script>
```
```js
Lerc.decode(xhrResponse, {
  pixelType: "U8", // leave pixelType out in favor of F32 for lerc1
  inputOffset: 10 // start from the 10th byte
});
```

## Node

```js
npm install 'lerc'
```
```js
var http = require('http');
var Lerc = require('lerc');

http.get('http://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer/tile/0/0/0', function (res) {
  var data = [];
  res.on('data', function (chunk) {
    // append each chunk to a list of buffer objects
    data.push(chunk);
  })
  res.on('end', function () {
    // turn the list into one large Buffer
    data = Buffer.concat(data);
    // because the decoder expects an ArrayBuffer
    var image = Lerc.decode(data.buffer);
    console.log("width of output is: " + image.width);
  })
});

// more info: https://github.com/dcodeIO/protobuf.js/wiki/How-to-read-binary-data-in-the-browser-or-under-node.js%3F
```

## API Reference

{{>main}}
* * *

## Licensing

Copyright 2017 Esri

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License.

A local copy of the license and additional notices are located with the source distribution at:

http://github.com/Esri/lerc/

[](Esri Tags: raster, image, encoding, encoded, decoding, decoded, compression, codec, lerc)
[](Esri Language: JS, JavaScript, Python)
