Skip to content

Commit

Permalink
fix(dev): read file as buffer (#398)
Browse files Browse the repository at this point in the history
fix #395
  • Loading branch information
underfin authored Jun 18, 2020
1 parent 91f696b commit 5ee1d15
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/node/server/serverPluginVue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ async function resolveSrcImport(
const importee = cleanUrl(resolveImport(root, importer, block.src!, resolver))
const filePath = resolver.requestToFile(importee)
await cachedRead(ctx, filePath)
block.content = ctx.body
block.content = (ctx.body as Buffer).toString()

// register HMR import relationship
debugHmr(` ${importer} imports ${importee}`)
Expand Down
7 changes: 4 additions & 3 deletions src/node/utils/fsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const getETag = require('etag')
interface CacheEntry {
lastModified: number
etag: string
content: string
content: Buffer
}

const fsReadCache = new LRUCache<string, CacheEntry>({
Expand All @@ -26,7 +26,7 @@ const fsReadCache = new LRUCache<string, CacheEntry>({
export async function cachedRead(
ctx: Context | null,
file: string
): Promise<string> {
): Promise<Buffer> {
const lastModified = fs.statSync(file).mtimeMs
const cached = fsReadCache.get(file)
if (ctx) {
Expand All @@ -51,7 +51,8 @@ export async function cachedRead(
}
return cached.content
}
const content = await fs.readFile(file, 'utf-8')
// #395 some file is an binary file, eg. font
const content = await fs.readFile(file)
const etag = getETag(content)
fsReadCache.set(file, {
content,
Expand Down

0 comments on commit 5ee1d15

Please sign in to comment.