Skip to content

Commit 626fdf4

Browse files
committed
Init
0 parents  commit 626fdf4

File tree

14 files changed

+8106
-0
lines changed

14 files changed

+8106
-0
lines changed

.gitignore

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
/target
2+
Cargo.lock
3+
4+
# Created by https://www.gitignore.io/api/windows
5+
# Edit at https://www.gitignore.io/?templates=windows
6+
7+
### Windows ###
8+
# Windows thumbnail cache files
9+
Thumbs.db
10+
Thumbs.db:encryptable
11+
ehthumbs.db
12+
ehthumbs_vista.db
13+
14+
# Dump file
15+
*.stackdump
16+
17+
# Folder config file
18+
[Dd]esktop.ini
19+
20+
# Recycle Bin used on file shares
21+
$RECYCLE.BIN/
22+
23+
# Windows Installer files
24+
*.cab
25+
*.msi
26+
*.msix
27+
*.msm
28+
*.msp
29+
30+
# Windows shortcuts
31+
*.lnk
32+
33+
# End of https://www.gitignore.io/api/windows
34+
35+
# Created by https://www.gitignore.io/api/macos
36+
# Edit at https://www.gitignore.io/?templates=macos
37+
38+
### macOS ###
39+
# General
40+
.DS_Store
41+
.AppleDouble
42+
.LSOverride
43+
44+
# Icon must end with two \r
45+
Icon
46+
47+
# Thumbnails
48+
._*
49+
50+
# Files that might appear in the root of a volume
51+
.DocumentRevisions-V100
52+
.fseventsd
53+
.Spotlight-V100
54+
.TemporaryItems
55+
.Trashes
56+
.VolumeIcon.icns
57+
.com.apple.timemachine.donotpresent
58+
59+
# Directories potentially created on remote AFP share
60+
.AppleDB
61+
.AppleDesktop
62+
Network Trash Folder
63+
Temporary Items
64+
.apdisk
65+
66+
# End of https://www.gitignore.io/api/macos
67+
68+
# Created by https://www.gitignore.io/api/node
69+
# Edit at https://www.gitignore.io/?templates=node
70+
71+
### Node ###
72+
# Logs
73+
logs
74+
*.log
75+
npm-debug.log*
76+
yarn-debug.log*
77+
yarn-error.log*
78+
lerna-debug.log*
79+
80+
# Diagnostic reports (https://nodejs.org/api/report.html)
81+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
82+
83+
# Runtime data
84+
pids
85+
*.pid
86+
*.seed
87+
*.pid.lock
88+
89+
# Directory for instrumented libs generated by jscoverage/JSCover
90+
lib-cov
91+
92+
# Coverage directory used by tools like istanbul
93+
coverage
94+
*.lcov
95+
96+
# nyc test coverage
97+
.nyc_output
98+
99+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
100+
.grunt
101+
102+
# Bower dependency directory (https://bower.io/)
103+
bower_components
104+
105+
# node-waf configuration
106+
.lock-wscript
107+
108+
# Compiled binary addons (https://nodejs.org/api/addons.html)
109+
build/Release
110+
111+
# Dependency directories
112+
node_modules/
113+
jspm_packages/
114+
115+
# TypeScript v1 declaration files
116+
typings/
117+
118+
# TypeScript cache
119+
*.tsbuildinfo
120+
121+
# Optional npm cache directory
122+
.npm
123+
124+
# Optional eslint cache
125+
.eslintcache
126+
127+
# Optional REPL history
128+
.node_repl_history
129+
130+
# Output of 'npm pack'
131+
*.tgz
132+
133+
# Yarn Integrity file
134+
.yarn-integrity
135+
136+
# dotenv environment variables file
137+
.env
138+
.env.test
139+
140+
# parcel-bundler cache (https://parceljs.org/)
141+
.cache
142+
143+
# next.js build output
144+
.next
145+
146+
# nuxt.js build output
147+
.nuxt
148+
149+
# rollup.js default build output
150+
dist/
151+
152+
# Uncomment the public line if your project uses Gatsby
153+
# https://nextjs.org/blog/next-9-1#public-directory-support
154+
# https://create-react-app.dev/docs/using-the-public-folder/#docsNav
155+
# public
156+
157+
# Storybook build outputs
158+
.out
159+
.storybook-out
160+
161+
# vuepress build output
162+
.vuepress/dist
163+
164+
# Serverless directories
165+
.serverless/
166+
167+
# FuseBox cache
168+
.fusebox/
169+
170+
# DynamoDB Local files
171+
.dynamodb/
172+
173+
# Temporary folders
174+
tmp/
175+
temp/
176+
177+
# End of https://www.gitignore.io/api/node
178+
179+
*.node

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[workspace]
2+
members = [
3+
"./packages/png"
4+
]

lerna.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"packages": [
3+
"packages/*"
4+
],
5+
"npmClient": "yarn",
6+
"useWorkspaces": true,
7+
"version": "0.0.0"
8+
}

package.json

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"name": "node-rs",
3+
"version": "0.0.0",
4+
"description": "Node & Rust bindings monorepo",
5+
"main": "index.js",
6+
"author": "LongYinan <[email protected]>",
7+
"license": "MIT",
8+
"private": true,
9+
"workspaces": [
10+
"packages/*"
11+
],
12+
"dependencies": {
13+
"napi-rs": "../napi-rs"
14+
},
15+
"devDependencies": {
16+
"@types/sharp": "^0.24.0",
17+
"@typescript-eslint/eslint-plugin": "^2.24.0",
18+
"@typescript-eslint/parser": "^2.24.0",
19+
"ava": "^3.5.0",
20+
"benchmark": "^2.1.4",
21+
"codecov": "^3.6.5",
22+
"eslint": "^6.8.0",
23+
"eslint-config-prettier": "^6.10.0",
24+
"eslint-plugin-import": "^2.20.1",
25+
"eslint-plugin-prettier": "^3.1.2",
26+
"eslint-plugin-react": "^7.19.0",
27+
"eslint-plugin-react-hooks": "^2.5.0",
28+
"eslint-plugin-sonarjs": "^0.5.0",
29+
"husky": "^4.2.3",
30+
"lerna": "^3.20.2",
31+
"nyc": "^15.0.0",
32+
"prettier": "^1.19.1",
33+
"sharp": "^0.25.1",
34+
"ts-node": "^8.6.2",
35+
"typescript": "^3.8.3"
36+
},
37+
"ava": {
38+
"extensions": [
39+
"ts"
40+
],
41+
"require": [
42+
"ts-node/register"
43+
],
44+
"files": [
45+
"packages/**/*.spec.ts"
46+
]
47+
},
48+
"lint-staged": {
49+
"*.@(js|ts|tsx)": [
50+
"prettier --write",
51+
"eslint -c .eslintrc.yml --fix"
52+
],
53+
"*.rs": [
54+
"cargo fmt"
55+
]
56+
},
57+
"prettier": {
58+
"printWidth": 120,
59+
"semi": false,
60+
"trailingComma": "all",
61+
"singleQuote": true,
62+
"arrowParens": "always",
63+
"parser": "typescript"
64+
},
65+
"husky": {
66+
"hooks": {
67+
"pre-commit": "lint-staged"
68+
}
69+
}
70+
}

packages/png/Cargo.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "png"
3+
version = "0.1.0"
4+
authors = ["LongYinan <[email protected]>"]
5+
edition = "2018"
6+
7+
[lib]
8+
crate-type = ["cdylib"]
9+
10+
[dependencies]
11+
futures = { version = "0.3", features = ["default", "thread-pool"] }
12+
image = "0.23"
13+
napi-rs = { version = "0.2", path = "../../../napi-rs/napi" }
14+
once_cell = "1.3"
15+
16+
[build-dependencies]
17+
napi-build = { version = "0.1", path = "../../../napi-rs/build" }

packages/png/build.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
extern crate napi_build;
2+
3+
fn main() {
4+
napi_build::setup();
5+
}
11.7 KB
Loading
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import path from 'path'
2+
import fs from 'fs'
3+
import sharp from 'sharp'
4+
import test from 'ava'
5+
import { promisify } from 'util'
6+
7+
const readFileAsync = promisify(fs.readFile)
8+
9+
import { decode } from '../index'
10+
11+
test('should decode png', async (t) => {
12+
const pngPath = path.join(__dirname, 'fixtures', 'sigi.png')
13+
const pngData = await readFileAsync(pngPath)
14+
const pixels = await decode(pngData)
15+
console.log(pixels)
16+
const sharpPixels = await sharp(pngData)
17+
.raw()
18+
.toBuffer()
19+
console.log(sharpPixels)
20+
t.is(pixels.length, sharpPixels.length)
21+
// t.deepEqual(pixels, sharpPixels)
22+
})

packages/png/lib/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export function decode(filepath: string | Buffer): Promise<Buffer>

packages/png/lib/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const fs = require('fs')
2+
const { promisify } = require('util')
3+
4+
const readFileAsync = promisify(fs.readFile)
5+
6+
const { decode: nativeDecode } = require('../index.node')
7+
8+
module.exports.decode = async function decode(filepathOrBuffer) {
9+
if (Buffer.isBuffer(filepathOrBuffer)) {
10+
return nativeDecode(filepathOrBuffer)
11+
}
12+
const pngData = await readFileAsync(filepathOrBuffer)
13+
return nativeDecode(pngData)
14+
}

0 commit comments

Comments
 (0)