Skip to content

Instantly share code, notes, and snippets.

@japboy
Created October 13, 2016 15:42
Show Gist options
  • Select an option

  • Save japboy/4ec74686d46d2a99132ae38ecedf4bc3 to your computer and use it in GitHub Desktop.

Select an option

Save japboy/4ec74686d46d2a99132ae38ecedf4bc3 to your computer and use it in GitHub Desktop.

Revisions

  1. japboy created this gist Oct 13, 2016.
    20 changes: 20 additions & 0 deletions encode.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    /**
    * UTF-8 から SJIS に一括変換するスクリプト
    */

    const fs = require('fs');

    const glob = require('glob');
    const iconv = require('iconv');

    const pattern = './assets/**/*';
    const files = glob.sync(pattern).filter((file) => fs.statSync(file).isFile());

    files.forEach((file) => {
    const conv = new iconv.Iconv('UTF-8', 'SHIFT_JIS');
    const filein = fs.createReadStream(file);
    const fileout = fs.createWriteStream(file);
    filein
    .pipe(conv)
    .pipe(fileout);
    });